LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 09-04-2009, 11:36 AM   #1
vjramana
Member
 
Registered: Sep 2009
Posts: 88

Rep: Reputation: 0
Unhappy 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
 
Old 09-04-2009, 01:21 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
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
 
Old 09-06-2009, 10:28 PM   #3
vjramana
Member
 
Registered: Sep 2009
Posts: 88

Original Poster
Rep: Reputation: 0
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
...
...
..
..
 
Old 05-17-2010, 12:43 AM   #4
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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!

Last edited by paulsm4; 05-17-2010 at 12:43 AM. Reason: Whoops - old post!!!!!!!
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenOffice Spreadsheet - Total All "Numerical" Values in a Column dudeman41465 Linux - Software 1 05-01-2009 10:21 AM
Change column value with AWK RyudoBlaze Programming 2 04-25-2009 04:05 AM
Concatenate column 1 and column 2 of related lines cgcamal Programming 4 11-20-2008 11:43 AM
awk command to multipy $(field) by numerical constant? johnpaulodonnell Linux - Newbie 3 01-31-2007 07:43 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 10:19 AM


All times are GMT -5. The time now is 07:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration