add up the numbers fast
From: Smith (smith_at_microsoft.com)
Date: Mon, 7 Nov 2005 22:42:18 +0800
i have a file (name listfile.dat) that has a list of numbers, example
etc.. I have 8000 lines. I want to add up all the numbers.
I'm using a while loop,
while [ $loop_cnt -le 8000 ]
line=`tail -$loop_cnt listfile.dat |head -1`
numtoadd=`echo $line|cut -f1 -d" "`
tot_count=`expr $tot_count + $numtoadd`
loop_cnt=`expr $loop_cnt + 1`
It should works but it took very long to run. Is there a more efficient way
of doing it?