Computing.Net > Forums > Unix > copy lines in vi from other file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

copy lines in vi from other file

Reply to Message Icon

Name: pnbalaji
Date: April 7, 2009 at 08:08:03 Pacific
OS: Windows XP SP3
CPU/Ram: 2GB RAM
Product: Dell / OPTIPLEX 755
Subcategory: General
Comment:

Hi,

I am changing 5 components in AIX-UNIX using vi editor. The issue is I need to write the following change log in all the components that I change.

Log Userid Date Change Description
=== ===== ======== ================
101 bna 04/07/2009 Include PRT309 in SP
=== ===== ======== ================

I entered these comments in one of the component. While editing the second file, is there a way to copy the above lines from the first file and paste them in the second file (or to 3rd, 4th or 5th file)?

Please help.

Thanks,
Balaji.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: April 7, 2009 at 08:49:23 Pacific
Reply:

In vi, here are two ways to do what you want:

1) From the command mode, press : and then input the line numbers, w, and the file name. The following example copies lines 43 to 52 to a new file newfile:

:43,52w newfile

This appends to newfile:

:43,52w>> newfile

2) Another way is to use named buffers. From the cursor in command mode, this line copies 5 lines into named buffer a:

"a5yy

now, to copy that named buffer to another file, change to the newfile name using the e syntax:

:e newfile

To place the contents of buffer a below the cursor:

"ap

To go back to the original file:

:e#

You have to save any changes to newfile before you go back to the original file.


0

Response Number 2
Name: pnbalaji
Date: April 7, 2009 at 09:47:08 Pacific
Reply:

Thanks, this is what exactly I want. The named buffer approach is really useful.

Thanks,
Balaji.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Merge multiple files line... installation of unix


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: copy lines in vi from other file

emacs copy question www.computing.net/answers/unix/emacs-copy-question/7807.html

files copy from other system www.computing.net/answers/unix/files-copy-from-other-system/7227.html

remove top line in file www.computing.net/answers/unix/remove-top-line-in-file/4769.html