Lets say you have a file which consists list of Numeric values and wish to add the total sum of all the numeric values. The bash syntax would be:
sum=0; for i in `cat filename.txt`; do sum=$(( $sum + $i )); done; echo $sum
(or)
declare -i sum=0; for i in `cat filename.txt`; do sum+=$i; done; echo $sum
sum=0; for i in `cat filename.txt`; do sum=$(( $sum + $i )); done; echo $sum
(or)
declare -i sum=0; for i in `cat filename.txt`; do sum+=$i; done; echo $sum
No comments:
Post a Comment