If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > append text to a file in Unix

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-06, 17:12
nandinir nandinir is offline
Registered User
 
Join Date: Jul 2005
Posts: 276
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?
Reply With Quote
  #2 (permalink)  
Old 12-08-06, 04:13
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
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 05:26. Reason: Added extracts from man pages for your info
Reply With Quote
  #3 (permalink)  
Old 12-08-06, 04:15
Tyveleyn Tyveleyn is offline
Registered User
 
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 04:21.
Reply With Quote
  #4 (permalink)  
Old 12-08-06, 13:16
nandinir nandinir is offline
Registered User
 
Join Date: Jul 2005
Posts: 276
Thank you very much. That helps.
Reply With Quote
  #5 (permalink)  
Old 12-12-06, 11:57
nandinir nandinir is offline
Registered User
 
Join Date: Jul 2005
Posts: 276
How can I copy text from a text-pad and paste in the vi editor window??
Reply With Quote
  #6 (permalink)  
Old 12-12-06, 18:04
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Depends on your terminal emulator. Check it's reference.

Regards
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On