Solved

Copy lines from one file to another using vi

Posted on 2002-03-10
10
353 Views
Last Modified: 2013-12-26
Using yyp I can copy and paste within the same file.  How can I copy lines of script from one file to another using vi.  
0
Comment
Question by:weeph
  • 5
  • 4
10 Comments
 
LVL 12

Expert Comment

by:tel2
ID: 6854965
weeph,

Try this example:

file1:
 A
 B
 C

file2:
 D
 E
 F

If you want to copy the E and F lines from file2 to file1, do this:
 vi file1 <Enter> To edit file1
 :e file2 <Enter> To swap file1 to file2
 <down-arrow>     To move the cursor to the "E" line
 "a               To open a buffer called "a" (for example)
 2yy              To copy (Yank) 2 lines to buffer "a"
 Ctrl-A           To swap back to file1
 "ap              To paste from buffer "a" at the current cursor position in file1

NOTE: Once you've made any changes to either file, you have to save then ":w", before you can swap with Ctrl-A.

Let me know how you get on with this.
0
 

Author Comment

by:weeph
ID: 6869027
Hi tel2
Tried your suggestion but all it did was to paste the same lines into file2.  I entered the key strokes as per your instructions saving file using w etc but when i did Ctrl-A it did not swap back to file1

weeph
0
 
LVL 12

Expert Comment

by:tel2
ID: 6873452
weeph,

Let's just try the swapping between files, first.  If we can get that working, we'll move on.  Try this:

vi file1<Enter>   To edit file1
:e file2<Enter>   (that's colon"e" file2) To swap from file1 to file2
Ctrl-A             To swap back to file1
Ctrl-A             To swap back to file2

Does that work?  If yes, the try again on by previous example.  If not, let me know what happened.

NOTE: Ctrl-A means to hold down "Ctrl", then press and release the "A" key (no need to press shift for upper case), then release the "Ctrl" key.

NOTE: In this example, and in my original example, you should NOT need the ":w" (that's colon"w"<Enter>).  That's only required if you want to swap files AFTER making changes to either file.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:weeph
ID: 6874829
Hi

No Ctrl+A doen't swap between files
Just beeps at me.  Using SCO 5.0.5 not that it should make any difference
weeph
0
 
LVL 12

Expert Comment

by:tel2
ID: 6874873
weeph,

Questions:
1. Does the ":e file2" swap to the file2?
2. How exactly do you do the Ctrl-A (ie: what exact key sequence)?  Sorry if this sounds basic, but I need to know.
0
 

Author Comment

by:weeph
ID: 6874914
Yes :e file2 swaps to file2
Press and hold Ctrl, tap A
weeph
0
 
LVL 12

Expert Comment

by:tel2
ID: 6874977
weeph,

Any error message (probably at the bottom of the screen) when it beeps at you when you press Ctrl-A?  If so, what is it?  If not, I think I admit defeat.
0
 

Author Comment

by:weeph
ID: 6875072
No error message sorry
weeph
0
 
LVL 1

Accepted Solution

by:
ilikenine earned 50 total points
ID: 6886145
Follow the same way as mentioned by tel2 for copying into cuffer and yanking (yy).
Now only problem is swaping between to files.
Do this in vi editor.
:e#
this will easy swap between two files.

to open two files you can say
vi <file1> <file2>

rest is ok i guess..
enjoy ving...
GG
0
 

Author Comment

by:weeph
ID: 6892501
Works like a charm. Thanx
weeph
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question