I have a text file:
$ cat text 542,8,1,418,1 542,9,1,418,1 301,34,1,689070,1 542,9,1,418,1 199,7,1,419,10
I would like to sort the file based on the first column and remove duplicates using sort , but everything is not going as expected.
Approach 1
$ sort -t, -u -b -k1n text 542,8,1,418,1 542,9,1,418,1 199,7,1,419,10 301,34,1,689070,1
It is not sorted based on the first column.
Approach 2
$ sort -t, -u -b -k1n,1n text 199,7,1,419,10 301,34,1,689070,1 542,8,1,418,1
It deletes the line 542,9,1,418,1 , but I want to keep one copy.
It seems that the first approach removes duplicates, but does not sort correctly, while the second sort correctly, but removes more than I want. How do I get the correct result?