Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I thought that sort would sort common prefixes together but that doesn't always happen. Take this input for example:

AT0S*eightieths
AT0S*eyetooth's
AT*ad
AT*Ad
AT*AD
AT*Eydie
AT*eyed
ATF*adv
ATF*ATV
ATF*edify
ATF*Ediva
ATFKT*advocate
ATFKTNK*advocating
ATFKT*outfought
ATFKTS*advocates
ATHT*whitehead
ATHT*Whitehead
AT*id
AT*I'd
AT*Ito
AT*IUD
ATJ*adage
ATNXNS*attention's
ATNXNS*attenuation's
ATNXNS*autoignition's
AT*oat
AT*OD
AT*outweigh
AT*owed
ATP0K*idiopathic
ATP*adobe
ATT*wighted
ATT*witted
ATT*wooded
AT*UT
AT*Uta
AT*wowed
AT*Wyatt
ATX*atishoo

After sort, I'd expect all the AT* to end up in one chunk but when you run this data through sort, the output == input. Why is that? I'm not specifying any option to ignore non-alphabetic characters or anything. Just sort dict > out.

My version of sort comes from coreutils 8.5-1ubuntu3.

share|improve this question
    
Works for me. Maybe an alias somewhere? –  Matthieu Cartier Dec 28 '10 at 12:18

3 Answers 3

up vote 7 down vote accepted

Setting LC_ALL=C restored the traditional sorting order in my case. Package: coreutils Version: 8.5-1ubuntu3

export LC_ALL=C 
share|improve this answer
    
LANG=C also works. What puzzles me: LANG is set to en_US.UTF-8; why is * still treated special?? –  Aaron Digulla Dec 28 '10 at 14:55
    
LC_COLLATE is the setting that's specific to sort, etc. –  Dennis Williamson Dec 28 '10 at 15:49
sort -V filename 

the -V flag should do the trick.

share|improve this answer
    
+1 That works but why? There are only a few single-digits in the text. –  Aaron Digulla Dec 28 '10 at 14:56

It works as expected for me (on cygwin).

sort input > output results in

AT*AD
AT*Ad
AT*Eydie
AT*I'd
AT*IUD
AT*Ito
AT*OD
AT*UT
AT*Uta
AT*Wyatt
AT*ad
AT*eyed
AT*id
AT*oat
AT*outweigh
AT*owed
AT*wowed
AT0S*eightieths
AT0S*eyetooth's
ATF*ATV
ATF*Ediva
ATF*adv
ATF*edify
ATFKT*advocate
ATFKT*outfought
ATFKTNK*advocating
ATFKTS*advocates
ATHT*Whitehead
ATHT*whitehead
ATJ*adage
ATNXNS*attention's
ATNXNS*attenuation's
ATNXNS*autoignition's
ATP*adobe
ATP0K*idiopathic
ATT*wighted
ATT*witted
ATT*wooded
ATX*atishoo

Is sort aliased to something? try \sort

Also

The locale specified by the environment affects sort order. Set LC_ALL=C to get the traditional sort order that uses native byte values

share|improve this answer
    
No alias. Must be some ubuntu/debian specific feature. –  Aaron Digulla Dec 28 '10 at 16:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.