2
When I sort foo
and foo1
, I expect foo
to come first, which is what happens ordinarily with unix sort
.
$ echo -e "foo1\nfoo" | sort
foo
foo1
But when I add and underscore and use the -t
and -k
options, it doesn't produce the same sort order.
$ echo -e "foo1_3\nfoo_3" | sort -t_ -k1
foo1_3
foo_3
What is the correct set of options to use to make foo_3
come before foo1_3
? I have LC_COLLATE=C
and am on Ubuntu 14.04.
PS: I never knew this and was always puzzled by sort -k's behaviour, untill this question triggered me to find out what was going on. So thanks a lot for asking! – reinierpost – 2015-09-25T08:15:42.107