summation script
Hello,
I have a very long list of Numbers like 116159 64625 55525 52981 40661 39653 39550 32807 32483 29250 28808 . . . 5 3 I wanna have the total sum , in fact I tried this code #!/bin/sh a=0 while read line do a=`expr $a + $line`; done < list.txt echo "Final Sum is: $a"; it gives me error like expr:Syntax error but it results the sum out , how come ? could someone help because I don't know if the result is correct or not .... |
There must be a blank line at the end of the file. The last expr fails - try using "sh -x your_script" for debugging and a smaller input file - e.g.
Code:
1 |
Yes exactly
but I tried to delete the blank line Code:
sed s'/^$//g' f1.txt > outf.txt |
let's have some awk then :)
Code:
awk '{count+=$1}END{print "total: " count}' file |
All times are GMT -5. The time now is 11:53 AM. |