CL: How to extract columns from a text file An Introduction to Durham, NC
Feb 01

Awk makes computing the average of a column of numbers in a text file very easy. Here’s the command for computing the average of the 5th column in a text file:

cat my_file.txt | awk '{sum=sum+$5}END{print sum/NR}'

The $5 means the 5th column and the NR means the number of entries (rows) in the column.

Leave a Reply