GNU/Linux command line tip of the day: sum of numbers in a column

28May

More often than not, I need to quickly need to see the sum of a column of numbers when I’m doing some processing on the GNU/Linux command line. For the sake of simplicity, let’s assume that you have the following output from some command line pipe:$ cat numbers.txt
1
2
3
4
5
6
7
8
9
10

So far I was generally employing awk or xargs, but I’ve decided to explore a simpler way and this is what I have discovered:

Of course it is possible to use Python, or simply invoke Perl to do a lot of fancy processing but I think as far as simplicity goes, those two solutions, especially the first one, is a nice addition to your Linux toolbox. Note that the first solution is really minimalist: the paste command is part of the GNU coreutils.