I need to sum numbers located in a file like this one:
column1 column2 column3
row1 a(1,1) a(1,2) a(1,3)
row2 a(2,1) a(2,2) a(2,3)
row3 a(3,1) a(3,2) a(3,3)
row4 a(4,1) a(4,2) a(4,3)
row5 a(5,1) a(5,2) a(5,3)
row6 a(6,1) a(6,2) a(6,3)
row7 a(7,1) a(7,2) a(7,3)
row8 a(8,1) a(8,2) a(8,3)
row9 a(9,1) a(9,2) a(9,3)
row10 a(10,1) a(10,2) a(10,3)
row11 a(11,1) a(11,2) a(11,3)
row12 a(12,1) a(12,2) a(12,3)
column4 column5 column6
row1 b(1,1) b(1,2) b(1,3)
row2 b(2,1) b(2,2) b(2,3)
row3 b(3,1) b(3,2) b(3,3)
row4 b(4,1) b(4,2) b(4,3)
row5 b(5,1) b(5,2) b(5,3)
row6 b(6,1) b(6,2) b(6,3)
row7 b(7,1) b(7,2) b(7,3)
row8 b(8,1) b(8,2) b(8,3)
row9 b(9,1) b(9,2) b(9,3)
row10 b(10,1) b(10,2) b(10,3)
row11 b(11,1) b(11,2) b(11,3)
row12 b(12,1) b(12,2) b(12,3)
the output should be like this:
column1 a(1,1)+a(2,1)+a(5,1)+a(6,1)+a(7,1)+a(8,1)+a(11,1) a(3,1)+a(4,1)+a(9,1)+a(10,1)+a(12,1)
column2 a(1,2)+a(2,2)+a(5,2)+a(6,2)+a(7,2)+a(8,2)+a(11,2) a(3,2)+a(4,2)+a(9,2)+a(10,2)+a(12,2)
column3 a(1,3)+a(2,3)+a(5,3)+a(6,3)+a(7,3)+a(8,3)+a(11,3) a(3,3)+a(4,3)+a(9,3)+a(10,3)+a(12,3)
column4 b(1,1)+b(2,1)+b(5,1)+b(6,1)+b(7,1)+b(8,1)+b(11,1) b(3,1)+b(4,1)+b(9,1)+b(10,1)+b(12,1)
column5 b(1,2)+b(2,2)+b(5,2)+b(6,2)+b(7,2)+b(8,2)+b(11,2) b(3,2)+b(4,2)+b(9,2)+b(10,2)+b(12,2)
column6 b(1,3)+b(2,3)+b(5,3)+b(6,3)+b(7,3)+b(8,3)+b(11,3) b(3,3)+b(4,3)+b(9,3)+b(10,3)+b(12,3)
I have a way to do something similar but which only its useful for 4 rows. I need o modify this script :
sed 's/row[1-9]//;/^$/d' file | #elimina os rows
pr -2t -w 1000|
awk 'NR==1{$1=$1; print; next}
!(NR%2){split($0,a); next}
{for(i=1;i<=NF;i++) $i+=a[i]}1' |
tr ' ' '\n' |
pr -3t
Note to compute sum use
$ tr -d 'ab(,)' < file > filenums
I think that it is necessary to do a modification in the awk section, but I do not know how to do that.
a(1,1)+a(2,1)+a(5,1)+a(6,1)+a(7,1)+a(8,1)+a(11,1)
anda(3,1)+a(4,1)+a(9,1)+a(10,1)+a(12,1)
instead ofa(1,1)+a(2,1)+a(3,1)+ ... +a(12,1)