add up the numbers fast
From: Smith (smith_at_microsoft.com)
Date: 11/07/05
- Next message: Mario Domgörgen: "Re: add up the numbers fast"
- Previous message: Bill Marcum: "Re: bash: fgrep and then use the line before"
- Next in thread: Mario Domgörgen: "Re: add up the numbers fast"
- Reply: Mario Domgörgen: "Re: add up the numbers fast"
- Reply: Bill Marcum: "Re: add up the numbers fast"
- Reply: John W. Krahn: "Re: add up the numbers fast"
- Reply: Chris F.A. Johnson: "Re: add up the numbers fast"
- Reply: Michael Tosch: "Re: add up the numbers fast"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 7 Nov 2005 22:42:18 +0800
Hi,
i have a file (name listfile.dat) that has a list of numbers, example
12
33
41
23
54
65
etc.. I have 8000 lines. I want to add up all the numbers.
I'm using a while loop,
while [ $loop_cnt -le 8000 ]
do
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`
done
It should works but it took very long to run. Is there a more efficient way
of doing it?
Regards
- Next message: Mario Domgörgen: "Re: add up the numbers fast"
- Previous message: Bill Marcum: "Re: bash: fgrep and then use the line before"
- Next in thread: Mario Domgörgen: "Re: add up the numbers fast"
- Reply: Mario Domgörgen: "Re: add up the numbers fast"
- Reply: Bill Marcum: "Re: add up the numbers fast"
- Reply: John W. Krahn: "Re: add up the numbers fast"
- Reply: Chris F.A. Johnson: "Re: add up the numbers fast"
- Reply: Michael Tosch: "Re: add up the numbers fast"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]