Results 1 to 3 of 3
Hello I am a first time poster here and seeking help with the Sort command under linux. I am trying to merge 4 text files into a single sorted text ...
- 04-16-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 1
Linux console command issues: Sort
Hello I am a first time poster here and seeking help with the Sort command under linux. I am trying to merge 4 text files into a single sorted text file and currently the Sort command works when I specify this command:
sort file1 file2 file3 file4 > new file
However the problem is that the sort is behaving in a different way to what I prefer. It will sort in this order:
A
a
B
b
However I need to sort all capital letters before lower case letters, e.g.
A
B
a
b
Can this be done using the sort command?
Thankyou
- 04-16-2010 #2
By default, it should sort by capitals first. You would need to pass the -f switch to sort to make it work otherwise. Is sort aliased in any way on your machine? Try:
$ type sort
- 04-17-2010 #3Just Joined!
- Join Date
- Jul 2008
- Posts
- 81
I think that sort(1) on your system is biased by the Locale settings. This is a moderately new idea, perhaps only 5 or so years old. To determine the locale, try the command:
$ locale
and look at the setting that controls sorting, namely LC_COLLATE.
You can work around this by adding to your sort command:
$ LC_COLLATE=POSIX; sort file1 file2 file3 file4 > new_file
This temporarily sets the locale to one in which capitals sort ahead of lower-case.
If you want to make this permanent, you can set the locale for yourself in your .bashrc
or set it for every user of the computer by editing /etc/sysconfig/i18n


Reply With Quote
