Unique sort with two fields

I have a file with contents below

123,502
123,506
123,702
234,101
235,104
456,104
456,100
 

i want to sort such that i get a unique value in column A, and for those with multiple value in A, i want the lowest value in B.

output should be

123,502
234,101
235,104
456,100

I need assistant . Thank you

This should do the trick:

$ sort -n input  | awk -F, '{if($1 in a){next}else{a[$1]++;print} }'

---------- Post updated at 01:02 AM ---------- Previous update was at 01:00 AM ----------

@ scottn: Your solution fails in this case:

$ cat cols
1230,502
1230,506
123,702
123,99
234,101
235,104
456,104
456,100
$ sort  -t, -k1,1 -u cols
123,702
1230,502
234,101
235,104
456,104

Numeric sort is needed

Yes, you're right, thanks :slight_smile: Is why I deleted, undeleted, then re-deleted my post!

it worked thanks