I need to sum the matrix elements of specific rows for each column. An example of the matrix is given below(input). So the matrix has 4 columns and 6 rows of numbers. I need to sum the numbers of specific rows for each column. I other words I need to sum the elements of row1 + row2 + row5 and row3 + row4 + row6 for each column.Input :   column1  column2 column3 column4         11.1     12       13     4               21.3     22       23     3                       31       32       33    45                 41       42       43   536                   23       32        6     5                         4        5        3     2                   The output should looks like this.  column1 column2 column3 column4        55.4    66      42      12    76      79      79     583I was trying to use awk like this: awk 'NR==1{$1=$1; print; next} !(NR%2){split($0,a); next} {for(i=1;i<=NF;i++) $i+=a[i]}1' filebut I cannot get the expected result.
How to sum specific rows of a matrix
shell script;text processing;awk
KISS implementation in awk:awk '    FNR == 1 {        n=NF;print;next    }     FNR == 2 || FNR == 3 || FNR == 6 {        for (i=1;i<=NF;i++) a[i]+=$i;    }     FNR == 4 || FNR == 5 || FNR == 7 {        for (i=1;i<=NF;i++) b[i]+=$i    } END {        for (i=1;i<=n;i++) printf(%8s, a[i]); print ;         for (i=1;i<=n;i++) printf(%8s, b[i]); print ;    }' file