Hi!!!
I have n decimal numbers in column:
1.23
3.45
5.16
.
.
.
How to do arithmetic sum of theese numbers???
Thanks!!!
awk '{ SUM += $1} END { print SUM }' file
$ ruby -ne 'BEGIN{s=0};s+=$_.to_f;END{print "Total: #{s}\n"}' file
Total: 9.84
Thanks!!!
I use this code before
awk '{ SUM += $1} END { print SUM }' file
-----------------------------------------------------------------
Example:
cat file
-------------
13.45
2.11
123.12
then awk gives me result 138??? (on my Centos)
on eeePC running Xandros result is correct!!!
What is the reason?
I don't see the problem in my env (CYGwin)
but you can try:
awk '{ SUM += $1} END { printf "%d", SUM }' infile
will show 138
awk '{ SUM += $1} END { printf "%.2f", SUM }' infile
will show 138.68