Merging rows with same column 1 value

I have the following space-delimited input:

1 11.785710 117.857100
1 15 150
1 20 200
1 25 250
3 2.142855 21.428550
3 25 250
22 1.071435 10.714350

The first field is the ID number, the second field is the percentage of the total points that the person has and the third column is the number of points they earn. I need to "merge" all of the records that have the same ID number. So, the output should be:

1 71.785710 717.857100
3 27.142855 271.428550
22 1.071435 10.714350

basically it's just adding the columns together of the rows with the same number in column 1. I tried a couple of different things using awk and arrays, but I can't seem to figure this one out.

Please help -- thank you

awk '{a[$1]+=$2;b[$1]+=$3}END{for (i in a) print i,a,b}' file
1 Like

Dear Bartus,

I also wanted to do same thing but also want to sum up the last column values.
Please help me for this.

thanks

Hello,

Please do not ask new questions in existing threads. Unless you have new information to a particular problem, please create a new thread in the appropriate forum.

Also, please search the forums first, as it might be that someone has already posted an answer for a similar problem.

Best regards,
The UNIX and Linux Forums