$ sort -n -t, -k1,2 test.dat | uniq 1,1 1,2 1,3 2,1 2,2 2,4 That's good.