Hello..
I have a file containg as below:
My need is to sum the values...
but the error is showing as interger conversion..so i put int() but again not working..please help..here is my code
Thanks in advance
esham
Hello..
I have a file containg as below:
My need is to sum the values...
but the error is showing as interger conversion..so i put int() but again not working..please help..here is my code
Thanks in advance
esham
here is a simple way to do it,
sed 's/M$//' filename | awk '{x += $0} END {print "total: " x "M"}'
Thank You...
that worked excellent...

If you dont mind ,can you explain the usage
sed 's/M$//' filename |
how sed gives the output..
is it one bt one or at a straigt the whole result...
the 's/M$//' replaces the M at the end of the line ($) with nothing then pipe to awk command
for replacing we have to give /g at the end..
or is that not needed..
that made me the confusion..

if you want to replace more than once you could add the 'g', but it this case there is only one end of line ($) per line so that was not necessary to add g unless you want to replace a lot of 'M's on the same line
fine got it..
Thanks for the detailed explanation...
Regards
Esham
You got the asnwer with awk + sed.. Lets try with awk only as,
awk '{ split($1,a,"M");x=x+a[1] } END { print "SUM: "x "M"}' filename
HTH.