Solved

Copy lines from one file to another using vi

Posted on 2002-03-10
10
352 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 11

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 11

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
 

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 11

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa‚Ķ
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now