Differences between revisions 3 and 4
Revision 3 as of 2008-11-22 16:45:30
Size: 482
Editor: GreyCat
Comment: formatting change
Revision 4 as of 2011-06-24 12:48:10
Size: 463
Editor: 195
Comment: fix link
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
For more examples of using {{{awk}}}, see [[http://www.student.northpark.edu/pemente/awk/awk1line.txt|handy one-liners for awk]]. For more examples of using {{{awk}}}, see [[http://www.pement.org/awk/awk1line.txt|handy one-liners for awk]].

How do I get the sum of all the numbers in a column?

This and all similar questions are best answered with an AWK one-liner.

awk '{sum += $1} END {print sum}' myfile

A small bit of effort can adapt this to most similar tasks (finding the average, skipping lines with the wrong number of fields, etc.).

For more examples of using awk, see handy one-liners for awk.

BashFAQ/076 (last edited 2011-06-25 15:19:06 by GreyCat)