Summing up records in large CSV with ack

A while ago I was using Powershell to help me with a mundane work on Windows. Today I’m on OS X and the task is simple. Sum up the third column in a CSV. But the problem is that the CSV is too large to be open and processed in Excel or Numbers.

We can deal with it by using awk – a language designed for text processing in shell.

awk -F ',' '{ x = x + $3 } END { print x }' test.csv

And with this simple one liner the calculation is done in a blink of an eye. UNIX tools proved to be powerful again.


Would you like to get the most interesting content about programming every Monday?
Sign up to Programming Digest and stay up to date!