Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2005
    Posts
    276

    Unanswered: append text to a file in Unix

    I need to know if we can append a text to a an existing file in Unix.
    If I'm in test.sql which has abcd in it
    and
    filename.sql has wxyz
    I used esc : r filename.sql which will append filename.sql to test.sql but at the beginning
    wxyz
    abcd

    Is there a way I can do it at the end..
    as

    abcd
    wxyz

    or simply copy wxyz and paste it in test.sql.
    Does anyone has any idea?

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    esc : $ r filename.sql

    extracts from man pages:
    Code:
    editing commands of the form:
    
              [ address [ , address ] ] command [ arguments ]
    
    --- snip, snip ---
    
         Addresses are constructed as follows:
    
         1.  The character "." addresses the current line.
    
         2.  The character "$" addresses the last line of the buffer.
    
         3.  A decimal number  n  addresses  the  n-th  line  of  the
             buffer.
    
    --- snip, snip ---
    
    
          Max Address      Command                 Description
         _________________________________________________________________
               2        r rfile          Read  the  contents  of   rfile.
                                         Place  them on the output...
    Last edited by pdreyer; 12-08-06 at 06:26. Reason: Added extracts from man pages for your info

  3. #3
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Hi,

    What you're talking about is appending files in a vi session. The lastline mode command 'r' inserts the specified file in the current file starting at the next line from where the cursor is. So if you want the external file to be inserted before the line with 'wxyz' make sure the cursor is on the previous line. If there's no previous line make one and delete it afterwards. If you need to append it to the end of the file go to the last line (or do it like pdreyer shows...)

    Regards
    Last edited by Tyveleyn; 12-08-06 at 05:21.

  4. #4
    Join Date
    Jul 2005
    Posts
    276
    Thank you very much. That helps.

  5. #5
    Join Date
    Jul 2005
    Posts
    276
    How can I copy text from a text-pad and paste in the vi editor window??

  6. #6
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Depends on your terminal emulator. Check it's reference.

    Regards

Posting Permissions

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