I have a huge matrix file containing some 1.5 million rows and 6000 columns. The matrix looks something like this:
1 2 3
4 5 6
7 8 9
3 4 5
I want to add all the numbers in the columns of this matrix and display the result to my stdout. This means that the numbers in the first column are:
1
4
7
3
When I add all of them up the result is 15 and in this way the sum of numbers present in the second column is 19 and third is 23. Hence my output should look like this:
15
19
23
I can add the numbers in the first column like this:
more matrix.mtx | awk '{sum+=$1} END {print sum}'
But don't know how to do it for the entire matrix of 6000 columns.
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.7 (lenny)
GNU bash 3.2.39
-----
Data file data1:
1 2 3
4 5 6
7 8 9
3 4 5
-----
Results with numsum:
15 19 23
Information about numsum ( package available in the Debian repositories ):
COPYRIGHT
numsum is part of the num-utils package, which is copyrighted by Suso
Banderas and released under the GPL license. Please read the COPYING
and LICENSE files that came with the num-utils package
Developers can read the GOALS file and contact me about providing
submitions or help for the project.
MORE INFO
More info on numsum can be found at:
http://suso.suso.org/programs/num-utils/
-- excerpt from man numsum