Results 1 to 6 of 6
I want to have the sort utility to be case sensitive. What I mean is if I have a file like this:
a
b
C
d
e
and sort it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 01-27-2010 #1Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
[SOLVED] How to make 'sort' case sensitive
I want to have the sort utility to be case sensitive. What I mean is if I have a file like this:
a
b
C
d
e
and sort it the upper-case C should be 1st. The output should be:
C
a
b
d
e
It seems sort is always case insentive (-f option) and I can't find a way to turn it off.
Thanks.
- 01-27-2010 #2
I don't think sort does that. I think it only would work numerically. But you can check for aliases in your system by running alias:
If you want text manipulation, I would suggest Perl.Code:# alias alias l.='ls -d .* --color=tty' alias ll='ls -l --color=tty' alias ls='ls --color=tty' alias mv='mv -i' alias rm='rm -i' alias vi='vim' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
- 01-27-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,143
Sort should work case-sensitive by default, unless you have an alias for sort that turns on the --ignore-case (-f) option. Most systems auto-alias commands like ls to give more "user friendly" output.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 01-27-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,143
Ok. I tried this on mine with the input being
a
b
c
A
B
C
and the output was
a
A
b
B
c
C
So, I guess you are correct. Seems like a bug to me...
However, msort with the proper options seems to work ok. The output for that was
A
B
C
a
b
c
which is what one would expect.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 01-27-2010 #5
Here is a Perl solution:
Code:#!/usr/bin/perl @letters= qw(a b C d e); print "Before letters:\n"; print "@letters\n"; @sorted_letters = sort @letters; print "After letters:\n"; print "@sorted_letters\n";
- 02-01-2010 #6Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Nope, it's not a bug it's a feature. ( Where have I heard that before?
) After some more digging around I determined that is the intended behaviour of GNU sort. To get (what I think is) the correct behaviour you have to set LC_ALL to "C".
Thanks eveyone for your suggestions.Code:# sort a.a a A b B c C # export LC_ALL=C # sort a.a A B C a b c




