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!

rearranging data 1

Status
Not open for further replies.

jmk2

Technical User
Apr 8, 2005
5
CA
Hi, I'm really new at awk/gawk/nawk and need help with what must be a simple problem, I have a test-inputdata set like this:

1 1
1 2
1 5
2 5
2 6
2 7
3 2
3 3
3 4
.
.
.
500 9
500 2
500 3

and I want the sum of all data with the same $1 (in other words when $1=1 sum up 1+2+5 (=8), when $1=2 sum up 5+6+7 (=18), etc... finally when $1=500 sum up 9+2+3 (=14)). I want the output to be:

1 8
2 18
3 9
.
.
.
500 14

thank you!!!
 
A starting point:
awk '{t[$1]+=$2}END{for(i in t)print i,t}' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
thanks PHV I'll give it a try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top