[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Copy lines from one file to another using vi

Posted on 2002-03-10
10
Medium Priority
?
359 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

649 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