Suppose I have file Marks.txt whose contents are
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2MTeGHbwJVzgc6VRYVU8RYXWpfrkhZDA3MESIVvg5Vc3OcOzZMowOCDOQf2s2PS-wdOoNgW-FHYXTpq9C1QjP6-Li6M4wonc8dWzs-o1pHjV5-G17bS_KVj9k-wU87M-vv2nHxqzMsteR/s280-rw/Marks.txt.gif)
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