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 03-24-2009, 12:13 PM   #1
Nick Edwards
LQ Newbie
 
Registered: Mar 2009
Location: Gloucester
Posts: 1

Rep: Reputation: 0
Substituting text 'Edit1' by lines n1 to n2


Dear Linux Questions,

I am using VIM.
I have placed at various locations in my file a line 'INSERT1' to denote where I wish to add text, which is usually many lines of existing text in the same file.

I wish to copy specified lines n1 to n2 of my file into some sort of buffer, and then replace every occurrence of text 'Insert1' in the same file by the lines n1 to n2. Ideally in one operation.

I am familiar with the simple substitution command of type :s n1, n2 /text1/text2/g but of course rather than specify 'text1', I wish to use specified line numbers.

I have the idea of some sort of SED command, but at this point my knowledge breaks down and I know LQ must have many members who have met this problem before.
Any help would be very gratefully received.

Postscript. None of my simple Unix books mentions any limits on the length of text one can have when using the substitution command :s n1, n2 /text1/text2/g and yet every system has limits.

With best wishes,
Nick Edwards
24 March 2009 17:10
 
Old 03-24-2009, 12:30 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this mite work:
Code:
sed -n s/insert1/`cat text.sub`/g file.txt
you mite need to escape special charecters.
 
  


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
Remove lines in a text file based on another text file asiandude Programming 10 01-29-2009 10:59 AM
Adding lines of text to beginning of a text file BillKat Programming 2 01-19-2009 10:40 AM
i am missing new lines when substituting with sed in a bash script FIRATYILDIRIM Programming 7 12-15-2008 03:07 PM
substituting or deleting a few characters in text i.you Linux - Software 3 12-19-2007 02:39 AM
Grab text lines in text file LULUSNATCH Programming 1 12-02-2005 10:55 AM

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

All times are GMT -5. The time now is 05:51 PM.

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