Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Given the file:

$ cat file
1
a
C
B
2
c
3
A
b

By default sort will:

$ sort file
1
2
3
a
A
b
B
c
C

With LC_COLLATE=C so will sort in uppercase letter before lowercase:

$ LC_COLLATE=C sort file
1
2
3
A
B
C
a
b
c

Is it possible to get sort to reverse the case ordering, that is digits, lowercase then uppercase?

share|improve this question
add comment

2 Answers

I'm no expert but I have never seen locale that defines collation like this. AFAIK this collation is only in C where it is based on ASCII values. (Normally I would just solve this by a script.)

However, I have never done this but you might want to look at localedef(1) and locale(5) manpages to get understanding of how locales are defined and eventually define your own one.

Also don't forget that if there are any diacritics or special characters, C locale will not treat them as you might want to. For example, it will not put á near a or Ł near L. In such cases, the language's native locale would be probably a better starting point.

share|improve this answer
add comment
LC_COLLATE="en_US.UTF-8"; sort file
share|improve this answer
    
This doesn't sort lowercase before uppercase? ideone.com/Gtyg4Z –  sudo_O May 10 '13 at 16:06
    
Hmm, in my case, it did using your example. –  unxnut May 10 '13 at 16:59
add comment

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.