Reputation: 53
I want to total the value in the 3rd and 4th columns of rows having the same value in column 2.
My file looks something like the following:
18 1600012 0 8
18 1600014 0 3
18 1600014 0 4
18 1600014 0 5
18 1600015 0 5
18 1600015 4 4
and the desired output would be
18 1600012 0 8
18 1600014 0 12
18 1600015 4 9
Upvotes: 1
Views: 57
Reputation: 785286
You can use awk like this:
awk '{k=$1 OFS $2; c3[k] += $3; c4[k] += $4} END{for (i in c3) print i, c3[i], c4[i]}' file
Output:
18 1600014 0 12
18 1600015 4 9
18 1600012 0 8
Upvotes: 1