LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using Vim to add something to the end of a series of a lines (https://www.linuxquestions.org/questions/linux-newbie-8/using-vim-to-add-something-to-the-end-of-a-series-of-a-lines-880790/)

Vim-Newbie 05-15-2011 01:08 AM

Using Vim to add something to the end of a series of a lines
 
I would like to use VIM to add something to the end of a series of lines. Ideally I could do something like add " X" (with a space before the X) to the end of lines 1-40 and 50-60 in a single command, i.e. ideally I could have a break in between where I didn't add something. If that's not possible just adding to 1-40 and 50-60 separately would work too.

I would be using bufdo to do this, but my understanding is that anything you can do in vim you can use with the bufdo command.

Thanks in advance!

catkin 05-15-2011 01:18 AM

For the single range of lines:
Code:

:1,40s/$/ X/

Vim-Newbie 05-23-2011 02:41 PM

Thanks, that's a huge help. I think that resolves things.

MTK358 05-23-2011 02:47 PM

You can also do it with sed:

Code:

sed '1,40 s/.*/& X/ ; 50,60 s/.*/& X/'


All times are GMT -5. The time now is 10:49 PM.