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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read file and add the data

Status
Not open for further replies.

smithia6

Technical User
Aug 28, 2002
35
US
Hello.

I have a file that looks like this below.

3.2
1.1
0.5
0.2
0.2
0.2
0.1
0.1
0.1
0.1
0.1
0.1
0.1
0.1

I wander if anyone has a way to read this line by line and add up the totals and send it to another file.

This file can have as many as 100 lines and as little as 4 so I never know how big it is going to be.

Regards

Ian
 
Try this :
[tt]
awk '{ total += $1 } END { print total }' input_file > total_file
[/tt]

Jean Pierre.
 
awk would be my choice:-
[tt]
awk '{sum+=$1} END {print sum}' file
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top