Register
It is currently Mon Nov 24, 2014 6:34 pm

Sum a given line using awk


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed Aug 15, 2012 9:14 am   

Joined: Sat Nov 07, 2009 5:00 pm
Posts: 7
I have a file with this entries :

Quote:
1224.62
1227.71
1230.81
1233.9
1236.99
1240.07
1243.17
1246.25
1249.35
1252.44
1255.53
1258.62
1261.72
1264.82



I'd like to sum it from a given line to another given line , for exemple line 5 until line 10
how can I do this using awk ?

thank you


Top
 Profile  
 PostPosted: Wed Aug 15, 2012 10:08 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 568
hi

test NR.


Top
 Profile  
 PostPosted: Fri Sep 07, 2012 8:08 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Code:
awk 'NR == first, NR == last { sum += $1 } END { print sum }' first=5 last=10 file


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP