I have
chr pos C T A G
NC_044998.1 3732 21 0 0 0
NC_044998.1 3733 22 0 2 0
NC_044998.1 3734 22 0 5 0
NC_044998.1 3735 22 0 0 0
NC_044998.1 3736 0 0 7 0
NC_044998.1 3737 0 0 0 22
NC_044998.1 3738 20 0 0 0
NC_044998.1 3739 1 0 22 0
NC_044998.1 3740 0 22 0 0
NC_044998.1 3741 22 0 0 0
I need to output the max value in $3 to $7 per line as well as the column name associated with it.
so that I have
chr pos max ref
NC_044998.1 3732 21 C
NC_044998.1 3733 22 C
NC_044998.1 3734 22 C
NC_044998.1 3735 22 C
NC_044998.1 3736 7 A
NC_044998.1 3737 22 G
NC_044998.1 3738 20 C
NC_044998.1 3739 22 A
NC_044998.1 3740 22 T
NC_044998.1 3741 22 C
I'm trying to adapt this:
awk 'NR == 1 {for (c = 3; c <= NF; i++) headers[c] = $c; next} {maxc=3;for(c=4;c<=NF;c++)if($c>$maxc){maxc=c} printf "max:%s, %s\n", $maxc, headers[maxc]}'
but it just output this max value
also have tried
awk '{maxc=3;for(c=4;c<=NF;c++)if($c>$maxc){maxc=c; $maxc = headers[c]} printf "max:%s, column:%s, column:%s\n",$maxc, maxc, headers[maxc]}'
Another issue I'm trying to figure is in cases where there's a tie between one or more columns. In that case I would like to print the max and the names of all columns associated.