I tried to sort the content of a file in Ubuntu desktop 14.04 (Trusty Tahr). In my case, the expected result should be same as original content, but the actual result is not. Why?
# cat test.txt
a++-a
a++-b
a++-c
ab
ac
# cat test.txt | sort
a++-a
ab
a++-b
ac
a++-c
Best Answer
You could use
LC_ALL
variable, set it toLC_ALL=C
before callingsort
Read this answer, if you want to know what is this magically
LC_ALL=C
. Here is short summary:Also, as @KenMollerup pointed, quote from
man sort
So when using sort with
LC_ALL=C
, sort compare symbols bytewise. Otherwisesort
will ignore all non alphanumerical characters.