#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Algeria
    Posts
    2
    Rep Power
    0

    Question concatenate files ?


    Hi

    I want to write a UNIX shell script to concatenate 2 files:
    Assume that I have File1 and File2
    My need is to concatenate in the head of File2 the content of File1 without erasing File2
    The same thing that do tee ľa but in the head of the file not in end , is it possible ?

    Thanks for your Help !
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    your best unix friend is called 'man', so
    man cat
    will show you the manual pages of cat command
    if you don't have man, google for 'unix man cat'
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Algeria
    Posts
    2
    Rep Power
    0
    Hi,
    with cat file1 file2 > file2
    can i be sure that i dont lose changes made on file2 if the commande take time ?

    Thanks
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    that will first zeroing file2
    Last edited by guggach; December 23rd, 2004 at 06:12 AM. Reason: typo
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Prague, Czech Rep.
    Posts
    117
    Rep Power
    15
    Originally Posted by slimanesadouki
    Hi,
    with cat file1 file2 > file2
    can i be sure that i dont lose changes made on file2 if the commande take time ?

    Thanks
    This is not correct. Read in some tutorial about expanding of the command line. The redirection is made before sending the command to the lower structures of Unix. Your command only deletes the file2 and then catinates file1 into file2. The only possibility is to use a temporary file and then rename it:

    cat file1 file2 > file3
    mv file3 file2

    I have made the same error many years ago too...

IMN logo majestic logo threadwatch logo seochat tools logo