Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Just Joined! hunter_thom's Avatar
    Join Date
    Apr 2010
    Posts
    89
    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

  3. #3
    Just Joined!
    Join Date
    Jul 2008
    Posts
    81
    Quote Originally Posted by Placebobecalp View Post
    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
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...