Differences between revisions 1 and 2
Revision 1 as of 2007-05-03 00:12:33
Size: 478
Editor: redondos
Comment:
Revision 2 as of 2008-11-22 14:09:10
Size: 480
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[Anchor(faq76)]] <<Anchor(faq76)>>
Line 3: Line 3:
This and all similar questions are best answered with an ["AWK"] one-liner. This and all similar questions are best answered with an [[AWK]] one-liner.
Line 10: Line 10:
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.student.northpark.edu/pemente/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)