LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Concatenate multiple data in vi (https://www.linuxquestions.org/questions/linux-newbie-8/concatenate-multiple-data-in-vi-4175421814/)

bison72 08-13-2012 03:52 AM

Concatenate multiple data in vi
 
Hi there, I have an issue in concatenating data in vi. Let's say initially the lines are shown as below:

123
abc
xyz
456

321
def
xyz
456

and I want something like this:

123321
abcdef
xyzxyz
456456

Can anyone help me with this? Thanks a lot! :)

David the H. 08-13-2012 02:41 PM

Not sure if it works in straight vi, but I can do it in vim. Just use the block selection tool (ctrl+v), to highlight and 'd' the second block. Then move up to the end of the first line and simply 'p' paste it.

Of course this depends on there being two blocks of text that line up. If you're actually trying to do something fancier like concatenate line n with line n+m, then you'll have to do something like record a macro or write a script.

http://vim.wikia.com is a good place for looking up vim how-to stuff.

bison72 08-13-2012 08:11 PM

This is quite helpful. Thank you very much David!


All times are GMT -5. The time now is 01:25 AM.