reopen 824346 Looks like this bug even influenced you, i.e., you wrongly assume that GNU sort behaves as documented in sort(1), instead of comparing the _initial_ numeric strings of each line, as required by POSIX and implemented all around (including GNU coreutils).
<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html>: | -n Restrict the sort key to an initial numeric string, consisting | of optional <blank> characters, optional minus-sign, and zero | or more digits with an optional radix character and thousands | separators (as defined in the current locale), which shall be | sorted by arithmetic value. An empty digit string shall be | treated as zero. Leading zeros and signs on zeros shall not | affect ordering. * Michael Stone [2016-05-14 15:25 -0400]: > On Sat, May 14, 2016 at 08:15:18PM +0200, Carsten Hey wrote: > >This description reads as if this command: > > > > $ printf '%s\n' 'x 9' 'x 10' | sort -n > > x 10 > > x 9 > > > >… would produce the output of this command: > > > > $ printf '%s\n' 'x 9' 'x 10' | sort -V > > x 9 > > x 10 > > > >…, but instead, -n stops doing its magic after finding the first > >non-numeric, non-whitespace character. There is a short and simple > >way to summarize this behaviour. > > That's because you're attempting a numeric sort on the entire line, If that would be true, this would not work: $ printf '%s asdf\n' 10 9 | sort -n 9 asdf 10 asdf … and it would instead have the output of this command: $ printf '%s asdf\n' 10 9 | sort 10 asdf 9 asdf > which is a string rather than a number. If the line consisted of > only numbers, it would do what you expect: I know how this works, the documentation is wrong. > >printf '%s\n' '9' '10' | sort -n > 9 > 10 > > If you want to sort on the second field, then you need: > > >printf '%s\n' 'x 9' 'x 10' | sort -k2,2n > x 9 > x 10 Thanks, again, I know how this works, I do not need any related support. Regards Carsten

