The sort utility in Ubuntu 10.04 (Lucid) always sort by case-insensitive, just like if you specify --ignore-case to it.

The two sort just give the same result: 

echo -e "c\nb\nB\na" | sort
echo -e "c\nb\nB\na" | sort --ignore-case

But sometimes I want to sort by case-sensitive, so the upper-case letters come first, then lower-case letter. Is it possible?

link|improve this question

feedback

2 Answers

up vote 2 down vote accepted

Override the collation order.

echo -e "c\nb\nB\na" | LC_COLLATE=C sort
link|improve this answer
feedback

Interestingly, yet another sort order is available like this:

echo -e "c\nb\nB\na" | LC_COLLATE=C sort --ignore-case

which puts the uppercase letter before its corresponding lowercase letter.

Here is a comparison of their outputs (I added "d" and "D") in the en_US.UTF-8 locale (except where overridden):

  1. echo -e "d\nD\nc\nb\nB\na" | sort
  2. echo -e "d\nD\nc\nb\nB\na" | sort --ignore-case
  3. echo -e "d\nD\nc\nb\nB\na" | LC_COLLATE=C sort
  4. echo -e "d\nD\nc\nb\nB\na" | LC_COLLATE=C sort --ignore-case

Output:

1   2   3   4
-   -   -   -
a   a   B   a
b   b   D   B
B   B   a   b
c   c   b   c
d   d   c   D
D   D   d   d
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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