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}'
No comments:
Post a Comment