Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Use 'yy' to copy a line (or 'dd' to cut a line) and 'p' to paste. If you want to paste into a different file, then use 'yy' (or 'dd') to copy it, then open the second file from within vi with ':e', and paste it there
arrow down to the line you want to copy
arrow down to the line where you want to paste
Last edited by suicidaleggroll; 03-03-2014 at 03:56 PM.
well that makes sense...*insert facepalm*
That solved half my problem of moving them to a new file.
But how would I copy just the specific lines that the character string, for instance "cat" exists in? The file size is 1000 lines, and I cant seem to figure out how to copy all of the instances at once.
EDIT: I need the whole line, but only the ones that have the string "cat" in them.
Let's say you have file a.txt and b.txt. You want some of a.txt in b.txt
If the files are small
1) vi b.txt
2) navigate to where you want some of a.txt
3) type in two lines of "========="
4) put your cursor in between the two lines
[put cursor here]
5) :r a.txt
This should put all of a.txt in between your "=====" signs. I use the "=====" signs as markers so I know where a.txt is. Once I have deleted what I need and only have the lines I want, i then delete the "=====" lines
If the files are longer, then you can always do
1) cp a.txt a.txt.stage
2) vi a.txt.stage
Delete all lines you need so a.txt.stage only contains the lines you want
3) vi b.txt
4) navigate to where you want the excerpt to be
5) :r a.txt.stage
Two very handy vi tricks: using the "r" and "!"
"!" will run a command line. So if you want the output of a command inserted into a file you can do something like