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!

Calculating Totals 3

Status
Not open for further replies.

thunderkid

Technical User
Oct 26, 2000
54
US
I need to calculate the total for last two columns and print values in summary table. Sounds simple? I have tried modifying other scripts and searching the forum, but just don't get it. Below is sample data:

1 redx 55
1 redy 47
2 redx 23
2 redy 42
3 redx 50
3 redy 51
.
.
.
30 redx 30
30 redy 30

Desired:
1 102
2 65
3 101
.
.
.
30 60

thunderkid
 
{ a[$1] += $3 }
END { for (i in a) print i, a}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
awk '{t[$1]+=$3}END{for(i in t)print i,t|"sort -n"}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
vgersh99 & PHV
Thanks for your solutions. PHV, that was a nice touch for the sort on the output data. Both deserve a star!

thunderkid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top