I have a command which returns some numbers as follows:
$ls -l ${dbname}.ix* | awk '{print $5 }'
929792
36864
57344
73728
53248
114688
How can I find the sum of those numbers by piping this output into 'awk' or some other editor/command? Thanks a lot -A
Just off the top of my head:
ttotal=0
ls -l ${dbname}.ix* | awk '{print $5 } >tempdat
while read zf
do
tvalue="$zf"
ttotal=$((ttotal+tvalue))
done <tempdat
echo $ttotal
Note: to add, you could also try the following command with the "bc" option (calculator)
ttotal=$(echo $ttotal + $zf | bc)
$ls -l ${dbname}.ix* | awk '{print $5;s+=$5}END{print "Sum :" s}'
Regards
another way:
ls -l ${dbname}.ix* | awk '{sum+= $5; print $5 } END {print sum}'