Simple life, Complicated mind
Wednesday, December 7, 2011
use awk command to sum up numbers in a column
data.txt:
price: 1
price: 3
price: 5
price: 7
price: 9
# cat data.txt | awk -F'\t' '{s = s +$2} {print s} END{print "sum: " s}'
1
4
9
16
25
sum: 25
-F'\t' : use tab as a separator
The Unix Programming Environment P.118
1 comment:
Akhil
January 12, 2012 at 1:33 AM
Nice Article.
Some examples on
Find Command
and
Awk Command
Reply
Delete
Replies
Reply
Add comment
Load more...
‹
›
Home
View web version
Nice Article.
ReplyDeleteSome examples on Find Command and Awk Command