Hi
I have a file named Data
cat Data
1797548295
2420652689
513068908
1426750759
3229436285
2710691077
i want to sum all these lines, can we use any direct command for that in unix.
Thanks in advance.
Hi
I have a file named Data
cat Data
1797548295
2420652689
513068908
1426750759
3229436285
2710691077
i want to sum all these lines, can we use any direct command for that in unix.
Thanks in advance.
awk '{s+=$1} END { print "sum=", s} ' inputfilename
Just to add, to prevent seeing 1.20981e+10, use printf instead of print...
Or use Perl instead. (Sorry, couldn't resist !)
$
$ cat data
1797548295
2420652689
513068908
1426750759
3229436285
2710691077
$
$ perl -lne '$x+=$_; END{print "Sum = ",$x}' data
Sum = 12098148013
$
tyler_durden
... after all, no solution would be complete without a Perl one
and a shell version!
while read d;do s=$((s+d));done<data;echo $s
12098148013
/Lakris
Or:
paste -sd+ data|bc
With Perl:
perl -le'print eval join"+",<>' data
With Z Shell:
print ${(e)\$((${(j:+:)$(<data)}))}
Thank you so much Guys ...