-1

I have to count values in first column of a file for which the second column occurrences are the same , using Unix.

12,abn

23,abn

45,hh

52,hh

89,mm

89,mm

My output should be something like this:

35,abn

97,hh

178,mm

Any help?

1 Answer 1

1

With awk:

$ awk -F, -vOFS=, 'NF{a[$2]+=$1}END{for(i in a) print a[i],i}' file | sort -n
35,abn
97,hh
178,mm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .