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.

link|improve this question

57% accept rate
Works for me. Maybe an alias somewhere? – Matthieu Cartier Dec 28 '10 at 12:18
feedback

3 Answers

up vote 3 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 
link|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
feedback
sort -V filename 

the -V flag should do the trick.

link|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
feedback

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

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

Your Answer

 
or
required, but never shown

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