Hi
i need to calculate the total of a column from a file in ksh
vi file.txt
System : CBSE ent=0.1 me=Cap
Subject Maths Science
xxxxx 56 98
yyyy 89 67
ooo 67 32
Here i need to calculate only the total of Maths column alone i.e., 56+89+67
Please help..
bmk
2
Try like..
awk '{print $2}' test1.txt|grep '[0-9]'|awk '{sum+=$1} END {print sum}'
pamu
3
awk 's{a+=$2}
/Subject/{s=1}
END{print a}' file
I think, You don't need so much of pipes.
awk '$2 ~ /[0-9]/{sum+=$1} END {print sum}' test1.txt
Cheers,
Ranga
pamu
5
Highlighted one should be $2
.
And as per the OP's input it can be written as....
awk '{sum+=$2}END{print sum}' file