I have a tsv file that contains some values.  I want the sum of each column and total number of values and percentage values.Eg:file.tsv containsx     1     1     0     1     x     x     1     x1     1     x     0     0     x     1     x     00     0     x     1     1     x     1     1     x0     x     x     x     1     x     x     x     1(tsv file contain more than 4 rows)result:        x     1     1     0     1     x     x     1     x        1     1     x     0     0     x     1     x     0        0     0     x     1     1     x     1     1     x        0     x     x     x     1     x     x     x     1sum     1     2     1     1     3     0     2     2     1total   3     3     1     3     4     0     2     2     2percent 33    66    100   33    75    0     100   100   50I have used a sed script to calculate number of one and zero but that did not append  to the end of file. And in the result sum represents the addition of '1' present in the column, total is the number of zero and one in the column ignoring the value of x(non-numeric character).
How do I calculate the column percentage of a file?
shell script;text processing;python;perl
You can do this with awk, keeping track of numeric versus non-numeric columns and summarizing at the end:#!/usr/bin/awk -fBEGIN {    width = 0;}{       if (width < NF)        width = NF;    for (n = 1; n <= NF; ++n) {        if ( $n ~ /^[0-9]+$/ ) {            number[n] += $n;            total[n] += 1;        } else {            others[n] += $n;        }    }    print;    next;}END {    printf sum;    for (n = 1; n <= width; ++n) {        printf %5d, number[n];    }    printf \n;    printf total;    for (n = 1; n <= width; ++n) {        printf %5d, total[n];    }    printf \n;    printf percent;    for (n = 1; n <= width; ++n) {        if ( total[n] != 0) {            printf %5d, 100 * number[n] / total[n];        } else {            printf %5d, 0;        }    }    printf \n;}