Say I have this file.
$ cat a.txt c 1002 4 f 1001 1 d 1003 1 a 1001 3 e 1004 2 b 1001 2
I want to sort it by the second column, and then by the third column. Column two is numbers, and column 3 can be thought of as a string. I know that the following command works well.
$ sort -k2,2n -k3,3 a.txt f 1001 1 b 1001 2 a 1001 3 c 1002 4 d 1003 1 e 1004 2
However, I think sort -k2n a.txt should also work as long as it doesn't.
$ sort -k2n a.txt a 1001 3 b 1001 2 f 1001 1 c 1002 4 d 1003 1 e 1004 2
It seems to be sorted by column two, and then by column one instead of column three. Why is this happening? Is this a mistake or not? The reason sort -k2 a.txt works fine with the data above, since these numbers are only a fixed width.
My version of sorting is sort (GNU coreutils) 8.15 in cygwin.
source share