0

This question already has an answer here:

I have data in a .txt like this:

2   40
1   50
1   50
1   50
1   50
2   70
2   70
5   80
5   80
6   100

And I want to sum first column if the second column's rows match so I can get an output like this:

2   40
4   50
4   70
10  80
6   100

Thanks in advance!

marked as duplicate by Wildcard, roaima, G-Man, Archemar, Rui F Ribeiro Jan 30 '18 at 13:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

What about this?

awk '{b[$2]+=$1} END { for (i in b) { print b[i],i } } ' file.txt

Not the answer you're looking for? Browse other questions tagged or ask your own question.