I use sort file
ABC AB-C ABCDEFG-HI
I get
ABC AB-C ABCDEFG-HI
why does sort orders the string this way? how do I make it sort ‘-‘ alphabetically?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The solution provided by @cnicutar is correct, but the reason needs explanation which is why I’m giving a new answer.
After the discussion with @cnicutar where in the end I suspected a bug in coreutils’
sortI found that this sorting behavior is expected:So to
sort, your input seems to be mapped as follows:If you want pure ASCII sorting, you need to call
LC_ALL=C sort(temporarily set the locale toCwhen callingsortwhich means “standard” behavior without localization; you can also usePOSIXinstead ofC).On other Unixes this behavior seems to be different (tested on Mac OS X which userland tools are derived from FreeBSD), but
LC_ALL=C sortshould yield the same behavior across all POSIX systems.