Hi All ,
Want to know the "sum" of all the digits in below file called "/sample" .Could some one please let me know the script either command .
cat /sample
12
34
23
23
Best Regards,
Chinni .
Hi All ,
Want to know the "sum" of all the digits in below file called "/sample" .Could some one please let me know the script either command .
cat /sample
12
34
23
23
Best Regards,
Chinni .
awk '{sum+=$1} END {print sum}' ./sample
echo `sed -e 's/$/+/' /sample` 0 | bc
# OR
echo `tr '\n' '+' < /sample` 0 |bc
Or:
paste -sd+ sample|bc
printf "%d\n" $(( `tr -s '\n' '+' < /sample` 0 ))
Thank you very much for all ,who replied to my query .Its my first posting and really impresive looking all u r reponce .Sincere thanks to the person who started this forum .
-Chinni