0

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!

1 Answers1

3

What about this?

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