LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   numerical operation on selected lines and column using AWK program (https://www.linuxquestions.org/questions/linux-newbie-8/numerical-operation-on-selected-lines-and-column-using-awk-program-752675/)

vjramana 09-04-2009 10:36 AM

numerical operation on selected lines and column using AWK program
 
Dear linux experts.
I am new to linux especially using awk program.

I have a file with two thousand lines consisting first 7 lines with alphabets and the rest with few columns of numerical data.

What I want to do is to add all the numerical data starting from 8th line till line 1993.

I wonder how to write awk program to ignore the first 7 lines in the data file and start operate on the rest of the numbers.

Could anyone help me to give sample code on how to carry on with this kind of operation?

Thank you.
Vj

David the H. 09-04-2009 12:21 PM

Awk is field-based, meaning it's best for parsing out sections of files that appear in fields or other regularly-spaced patterns. While it is possible to use it here, sed is a much better choice for operating on lines.

This will print all lines from #8 to the end of the file:
Code:

sed -n '8,$p' file.txt
Another simple option is tail.
Code:

tail -n +8 file.txt

vjramana 09-06-2009 09:28 PM

Thank you so much for your kind. The sed code works fine to select the numerical data only. By the way, I have given sample data for which I want to do the calculation. Basically, 6 lines of the file contains sentences and empty lines. What I want to calculate is standard deviation for the Area column in the file ( 4th column) so I need to write awk script to ignore the first 6 lines and start read the numerical data to calculate standard deviation. If you have idea please suggest me.

Thanks in advance.

Vj

***********************************************************************************

Starting calculating Area per Lipid
Last five frames

Dimension-X Dimension-Y Dimension-Z Area(Y*Z) Volume(X*Y*Z)

90.885 47.081 49.391 2325.378 211341.9496
90.904 47.091 49.401 2326.342 211473.8378
90.863 47.070 49.379 2324.270 211190.1023
90.858 47.068 49.376 2324.030 211156.6785
90.839 47.058 49.366 2323.065 211024.9222
90.859 47.068 49.377 2324.077 211163.2791
90.819 47.047 49.355 2322.005 210882.1435
90.830 47.053 49.361 2322.583 210960.2260
90.853 47.065 49.374 2323.787 211123.0485
90.890 47.084 49.394 2325.667 211379.8824
90.934 47.107 49.417 2327.887 211684.0418
90.874 47.076 49.385 2324.848 211268.2608
90.941 47.111 49.421 2328.273 211735.4504
90.906 47.092 49.402 2326.439 211487.2623
90.849 47.063 49.371 2323.547 211091.9553
90.868 47.073 49.381 2324.512 211223.7394
90.873 47.075 49.384 2324.752 211257.1703
90.899 47.089 49.398 2326.102 211440.3841
90.885 47.081 49.391 2325.378 211341.9496
90.900 47.089 49.399 2326.150 211446.9905
90.811 47.044 49.351 2321.668 210833.0331
90.914 47.097 49.407 2326.921 211549.7393
90.856 47.066 49.375 2323.884 211138.7820
90.890 47.084 49.394 2325.667 211379.8824
90.924 47.102 49.412 2327.404 211616.8835
90.865 47.071 49.380 2324.366 211203.5148
90.912 47.096 49.406 2326.825 211536.3122
90.902 47.090 49.400 2326.246 211460.4139
90.806 47.041 49.348 2321.379 210795.1658
90.826 47.051 49.359 2322.390 210933.4222
90.853 47.065 49.373 2323.740 211118.7725
90.848 47.062 49.371 2323.498 211085.1465
90.929 47.105 49.415 2327.694 211654.8491
90.781 47.028 49.335 2320.126 210623.3929
90.786 47.031 49.337 2320.368 210656.9698
...
...
..
..

paulsm4 05-16-2010 11:43 PM

Hi -

I noticed in another post you're using FORTRAN.

You can do this in any language (including AWK or FORTRAN).

Q: What (if any) programming and/or scripting language do you feel most comfortable with?

Q: If the answer is "none", would you be interested in learning a script language like Perl or Python? Both of which are relatively easy to learn (arguably easier than either AWK or FORTRAN), and could easily accomplish this - and similar - tasks...

Just a thought .. PSM

PS: I didn't realize how old this post was. Sorry!


All times are GMT -5. The time now is 11:43 PM.