how can i calculate a file using awk

hi all
Am new to scripting...
So,i have a file named file1 its contents are as follows:

joy 55 66 77
ruby 77 88 99
saloni 88 44 33

I would require a script which will calculate its percentage,its total and the average with awk script

Many thanks in advance..
Please reply me at the earliest

regards
whizkid

Try someting like:

awk '{
t=$2+$3+$4
a=t/4
print $1,$2/t*100"% "$3/t*100"% "$4/t*100"%","tot="t,"average="a}
' file

hi franklin..
Many thanks for your help.
The above script helped me find row wise percentage,total and average..
How about column level wise(percentage,total,average)...Can we still modify the script .Pls let me knw

Name M1 M2 M3
joy 55 66 77
ruby 77 88 99
saloni 88 44 33

regards
Whizkid

Give it a try ~ First do file transposing (as showed here), then do the calculation by row on the transposed file.

awk '{
2t+=$2
3t+=$3
4t+=$4
t=$2+$3+$4
a=t/4
print $1,$2/t100"% "$3/t100"% "$4/t*100"%","tot="t,"average="a}
'
END { print "TOTALS" 2t 3t 4t } ' file