I have about 5000 columns of data that i need to convert all of it into pecentages. for shorter colums i have been using this code:
{print $1/($1+$2)*100,$2/($1+$2),$3/($3+$4)*100 .....}
but this is a teadious process... with help i got this
sed "s/[0-9]*.[0-9]*/&~/g" | tr "\n" " " | tr "~" "\n" | awk '$1*$2>0,z=$1+$2;x=$1/z;y=$2/z {print x,y}'
problem is it prints the input data before converting to %. also i need to code it in such a way that it does all 5000 columns at once... and outputs to lines corresponding to input..
sample data:
55 65 48 45 48 68 32 68 44 34 88 65
82 63 52 54 51 68 75 0 0 20 10 77
55 77 60 55 22 60 40 25 75 55 45 90
20 80 33 63 0 64 32 22 75 0 43 56
54 54 12 35 48 87 65 12 77 85 0 15
Output data:
45.83 54.16 51.61 48.38 .................... (all the columns are in pairs..$1 and $2 are a pair.. so while calculating column 3 and 4.. it would be $3/$3+4 and $4/$3+$4 .....$5/$5+$6, $6/($5,$6)
PS: there will be lines that will have to be divided by zero. in those cases i am using this code.. is it right? need to embedd it into the overall code as well..
if ($0 != 0) lines++; print 0
Thank you.