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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to copy character strings from one text file, and need to paste them in another (separate) file. Needless to say, I can't figure this one out.
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
Ex:
vi /path/to/first/file
arrow down to the line you want to copy
yy
:e /path/to/second/file
arrow down to the line where you want to paste
p
Last edited by suicidaleggroll; 03-03-2014 at 02: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.
Got it. Opened the two windows, and manually moved the files. At least that worked. Then remembered grep and >
Thanks for the input guys, learn something new every day right?
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.