Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2004
    Posts
    46

    Unanswered: sort on morethan 2 files

    Hi all,

    What is the unix sort command to sort 3 files x1.txt,x2.txt,x3.txt at the same time

    where i have to do sorting on the 4 keys(columns) on the 3 files and these four columns are same on the 3 files


    can any one help me how to do ?

    Thanks
    Jason.

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    do you want to create ONE sorted fiile out of 3 input files?

    what is your record/column separator?
    what columns do you need to sort on?

    man sort
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Jun 2004
    Posts
    46
    hi

    i need to sort 3 files and put the result in the same 3 input files (overwrite)
    three input files are comma delimited , i have tried on single key files but never on 4 key fields and on 3 files at a time....


    thanks
    jason

  4. #4
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    I don't think you can do what you want without writting a script wrapper.
    work out the details in the 'stand-alone' mode and write your script afterwards.

    Here's how to sort on 2 fields: second and fifth:

    sort -t ',' -k 2,2 -k 5,5 file
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  5. #5
    Join Date
    Jun 2004
    Posts
    46
    Thanks vgresh,

    I will try... what you said,... but i guess there is sort -o option to overwrite the same file...


    Thanks
    Jason

  6. #6
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    right, but I don't think you can do it for multiple files. I might be mistaken - you'll have to try it out in the 'sand-box' to see how far you can get.

    If you cannot do it for multiple files on the same command line, you'l' have to script it with some kind of a 'loop' - one file at the time.
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

Posting Permissions

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