tag 11900 + notabug
close 11900
stop
On 07/10/2012 08:42 AM, j...@smartots.com wrote:
> echo -e "1 qFeb\n1 qJan" | sort -k2.2,2.5M
Yep that's a tricky one, but specified by POSIX.
--debug is very useful here...
$ echo -e "1 qFeb\n1 qJan" | sort --debug -k2.2,2.5M
sort: using ‘en_US.utf8’ sorting rules
sort: leading blanks are significant in key 1; consider also specifying 'b'
1 qFeb
^ no match for key
__
1 qJan
^ no match for key
__
Now you might think you can just specify -b, but...
$ echo -e "1 qFeb\n1 qJan" | sort --debug -b -k2.2,2.5M
sort: using ‘en_US.utf8’ sorting rules
sort: leading blanks are significant in key 1; consider also specifying 'b'
sort: option '-b' is ignored
1 qFeb
^ no match for key
__
1 qJan
^ no match for key
__
So you might then think you could add 'b' to the full key, but...
$ echo -e "1 qFeb\n1 qJan" | sort --debug -b -k2.2,2.5Mb
sort: using ‘en_US.utf8’ sorting rules
sort: leading blanks are significant in key 1; consider also specifying 'b'
1 qFeb
^ no match for key
__
1 qJan
^ no match for key
__
So what you really need to do is:
$ echo -e "1 qFeb\n1 qJan" | sort --debug -k2.2b,2.5Mb
sort: using ‘en_US.utf8’ sorting rules
1 qJan
___
__
1 qFeb
___
__
cheers,
Pádraig.