Sort is sorting differently than I would expect. I have this file, call it text.txt
:
a 1
A 1
a 11
(the space is always one \t
)
I want to sort them alphabetically by the first column. However, when I do
sort -k 1 text.txt
all I got is the text.txt file, not sorted. If I do it by the deprecated + -
notation, meaning
sort +0 -1 text.txt
it works as it should, meaning that I get this output:
a 1
a 11
A 1
This strange behaviour occurs only when I have lines that differs only by case. What am I doing wrong?
A
would be beforea
. Most locales have a weird collation order; it's often best to keepLC_COLLATE=C
. On this issue, see Does (should) LC_COLLATE affect character ranges? Why are capital letters included in a range of lower-case letters in an awk regex?