Page 1 of 1

Bug in GNU sort?

Posted: Sat Mar 06, 2010 8:41 am
by jal
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:

Code: Select all

sort -k3,3 -k2,2n inp.txt
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:

Code: Select all

sort -n -k3,3f -k2,2 inp.txt
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

Re: Bug in GNU sort?

Posted: Sun Mar 14, 2010 9:58 pm
by KotuxGuy
man sort says:

Report sort bugs to [email protected]

I hope this isn't necroposting..

Re: Bug in GNU sort?

Posted: Tue Mar 16, 2010 4:26 am
by jal
KotuxGuy wrote:I hope this isn't necroposting..
Hardly. Thanks for that, now I'm a bit ashamed I didn't see that myself.


JAL

Re: Bug in GNU sort?

Posted: Tue Mar 16, 2010 5:53 pm
by KotuxGuy
No problem! :)