LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-15-2011, 02:08 AM   #1
Vim-Newbie
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
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
For the single range of lines:
Code:
:1,40s/$/ X/
 
1 members found this post helpful.
Old 05-23-2011, 03:41 PM   #3
Vim-Newbie
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
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

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

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


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:40 AM.

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