How to calculate mean in AWK

Another trick with awk to compute mean of a column.

Imagine that you have a file with many lines and you want to compute the mean of the fourth item on each line. E.g:

Lowest value found .2
Lowest value found .4
Lowest value found .6

Using the awk tool under Linux, type:

awk '{x+=$4; next} END{print x/NR}'

and you should get the answer.

Please follow and like us:
This entry was posted in Linux and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.