Andreas Schwab <address@hidden> writes:
> > However, it's still worrisome that "sort -k 5" doesn't work as it should.
>
> Note that the whitespace before the number is part of the sort key:
Good point. I missed that.
> So if you have right aligned numbers in a field, -n gives the same result
> as without -n.
That is true in the C locale, but it's not true for other locales.
When he sorts these two lines:
-rw-r--r-- 1 robertd users 2446 Aug 14 13:32 foobar
-rw-r--r-- 1 robertd users 678 Jul 10 15:15 baz
using "sort -k 5", he is comparing the following two strings:
" 2446 Aug 14 13:32 foobar"
" 678 Jul 10 15:15 baz"
My guess is that he's using some locale other than "C". In many
locales, digits have low priority in textual comparison, and since
"Aug" precedes "Jul" this comparison will result in "<", which isn't
what he wants.
If my guess is right, it's not a bug in "sort", as "sort" is operating
according to its specification. He should be using "sort -k 5,5n".