I have found very weird behaviour in sort on Linux, and I'm wondering if it's me doing something wrong, or whether there's a bug in there.
I have this input file:
Code: Select all
20 6 1234XX
12 10 1234XX
14 13 1234AA
I would like to sort on the third column first, then on the second column, but numerical, not ASCII. I figured this should do it:
However, the result comes out wrong:
Code: Select all
14 13 1234AA
12 10 1234XX
20 6 1234XX
Although the third column is sorted the way I want, the second isn't: 6 should come before 10. So I tried something slightly different:
But no such luck: though the 'f' triggers ASCII sorting, it also somehow prevents the second -k receiving the global -n. Then I tried to switch the columns in the input file:
Code: Select all
20 1234XX 6
12 1234XX 10
14 1234AA 13
And what do you know? Both "-k2,2 -k3,3n" and "-n -k2,2f -k3,3" produce the right, expected output:
Code: Select all
14 1234AA 13
20 1234XX 6
12 1234XX 10
I'm a bit lost here, as this is behaviour that is certainly not documented (not that "man sort" gives that many helpful information), and I would think this is a bug. If it is, where can I report it?
JAL