Register a domain and help support LQ
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This 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!


  Search this Thread
Old 05-15-2011, 02:08 AM   #1
LQ Newbie
Registered: May 2011
Posts: 2

Rep: Reputation: 0
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!
Old 05-15-2011, 02:18 AM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
For the single range of lines:
:1,40s/$/ X/
1 members found this post helpful.
Old 05-23-2011, 03:41 PM   #3
LQ Newbie
Registered: May 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks, that's a huge help. I think that resolves things.
Old 05-23-2011, 03:47 PM   #4
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
You can also do it with sed:

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add comma to end of lines in text file Johng Programming 9 08-21-2010 05:15 AM
gui read out of back end command lines from gui front end activation? how? Siljrath Linux - General 0 10-24-2008 11:11 AM
printer printing vertical lines at beginning and end of lines makhand Linux - Hardware 0 09-02-2005 03:03 PM
Assistance with extracting a series of lines from a log file katsal Linux - General 1 06-21-2005 07:55 PM
vim: mark end-of-line? trim blank lines? prell Linux - Software 3 09-21-2004 12:04 AM

All times are GMT -5. The time now is 11:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration