?
Solved

Copy lines from one file to another using vi

Posted on 2002-03-10
10
Medium Priority
?
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

752 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