awk is a small powerful tool for processing column oriented text data.
Suppose I have file Marks.txt whose contents are
Use the following command to calculate the sum of the entries in column 3
cat Marks.txt | awk '{sum+=$3} END {print "Total=", sum}'
To get the average, use the following command
cat Marks.txt | awk '{sum+= $3} END {print "Average=", sum/NR}'
Search This BlogApr 9, 2009Using awk to calculate sum/average
Subscribe to:
Post Comments
(
Atom
)
|
No comments :
Post a Comment