Hi,
I am trying to extracting the sum of all varibles listed in a file.
The code is as follows
##### FILE1 ########
Value1:2
Value2:2
Value3:6
Value4:5
##### shell script ######
#!/bin/sh
total=0
cat FILE1 | \
while read line
do
count=`echo $line | awk -F":" '{print $NF}'`
total=`expr $total + $count`
echo $total
done
echo $total
I get the o/p as
2
4
10
15
0 => wrong o/p for total
Inside the loop the variable is getting updated. But once out, the variable 'total' is back to 0.
Any way for solving this?