I'm trying to transform some data to a percent of the total of each column, very similar to this thread except that I need to do this for every column: Calculate and divide by total with AWK
Data would like something like this (but more columns and rows):
ID Sample1 Sample2 Sample3
One 10 0 5
Two 3 6 8
Three 3 4 7
And the desired output would look like this:
ID Sample1 Sample2 Sample3
One 62.50 0.0 25.0
Two 18.75 60.0 40.0
Three 18.75 40.0 35.0
The following works for a single column, but I want to do this for every column, except the first one.
gawk -F"\t" '{a[NR]=$1;x+=(b[NR]=$2)}END{while(++i<=NR)print a[i]"\t"100*b[i]/x}' file.txt
Thanks a lot for any help you might be.