Find the answer to your Linux question:
Results 1 to 8 of 8
Hi, I would like to add two files together {Keeping their respective ordering}.. e.g. file 'a' contains hi welcome to file 'b' contains bob linuxforums so that file 'c' contains ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    2

    Add two files {But keep their respective order}..

    Hi,
    I would like to add two files together {Keeping their respective ordering}..

    e.g. file 'a' contains
    hi
    welcome to

    file 'b' contains
    bob
    linuxforums

    so that file 'c' contains
    hi
    bob
    welcome to
    linuxforums

    If I use 'cat' the contents of file 'b' are appended to the bottom of file 'a'.

    I also tried using $ sed a\ fileb filea > filec {But fileb was interpreted as text as opposed to the contents of fileb}

    Any help would be greatly appreciated. {This is my first post }

    Thanks
    Stephen.

  2. #2
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    You can do this with join, but beware the utility is a major PITA.

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    You can do this with:
    Code:
    paste -d "\n" filename1 filename2
    likwid, how would you do this with join? I looked at the man page, and just don't see that happening.

  4. #4
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Why not simply with cat?

    Code:
    cat a b > c
    Regards

  5. #5
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Because suppose you have two files. File a contains this:
    Code:
    a1
    a2
    a3
    and file b contains this:
    Code:
    b1
    b2
    b3
    If you cat them you get this:
    Code:
    a1
    a2
    a3
    b1
    b2
    b3
    and the OP wanted this:
    Code:
    a1
    b1
    a2
    b2
    a3
    b3

  6. #6
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Oh my, I didn't read the question carefully , I apologize.

    Regards

  7. #7
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    You're right wje- I was half thinking of paste heh.

  8. #8
    Just Joined!
    Join Date
    Oct 2007
    Posts
    2
    Thanks very much, the past cmd worked..

    {Just changed the filename order - i.e paste -d "\n" filename2 filename1}

Posting Permissions

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