Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum total in for loop

Status
Not open for further replies.

ranjank

IS-IT--Management
May 9, 2003
176
IN
Hi,

I ant to do sum total of file and redirect to another in another file.

For E.g

cat count
3
4
5
99
123

i want the total of count file and redirect it to say SUM file.

Any pointers on this will be helpfull.

Regards,
Ranjan.
 
Hi,

Use awk this way :
Code:
awk '{S+=$1}END{print S}' /path/to/countfile > /tmp/SUM.file

 
total=0

cat $* |
while read line
do
echo "$total: $line"
(( total = $total + $line ))
done
echo "The Total is " $total

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top