Bug in GNU sort?

Programming, for all ages and all languages.
Post Reply
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Bug in GNU sort?

Post 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
User avatar
KotuxGuy
Member
Member
Posts: 96
Joined: Wed Nov 25, 2009 1:28 pm
Location: Somewhere within 10ft of my favorite chubby penguin!

Re: Bug in GNU sort?

Post by KotuxGuy »

man sort says:

Report sort bugs to [email protected]

I hope this isn't necroposting..
Give a man Linux, you feed the nearest optician ( Been staring at the PC too long again? ).
Give a man OS X, you feed the nearest NVidia outlet ( I need more GPU power!! )
Give a man Windows, you feed the entire Tylenol company ( Self explanatory :D )
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Bug in GNU sort?

Post 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
User avatar
KotuxGuy
Member
Member
Posts: 96
Joined: Wed Nov 25, 2009 1:28 pm
Location: Somewhere within 10ft of my favorite chubby penguin!

Re: Bug in GNU sort?

Post by KotuxGuy »

No problem! :)
Give a man Linux, you feed the nearest optician ( Been staring at the PC too long again? ).
Give a man OS X, you feed the nearest NVidia outlet ( I need more GPU power!! )
Give a man Windows, you feed the entire Tylenol company ( Self explanatory :D )
Post Reply