LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-29-2003, 03:33 AM   #1
meshcurrent
Member
 
Registered: Oct 2002
Posts: 38

Rep: Reputation: 15
Replacing String with File Content in Sed


Can Sed replace a string with text from a file?

Youssef Eldakar
Bibliotheca Alexandrina
 
Old 05-29-2003, 02:22 PM   #2
0x4B
Member
 
Registered: May 2003
Location: Nashville TN, USA
Distribution: Debian (I'm unstable)
Posts: 117

Rep: Reputation: 15
as a start, you can have sed replace a string with the contents of a variable, e.g.
tail some.file | sed "s/astring/$AVARIABLE/g"
the contents of the variable will be replace by the shell and then interpreted by sed. as a result, if the file contains anything that might be a control character (including other scripting commands) then it will choke. spaces are okay
 
Old 06-01-2003, 01:54 AM   #3
meshcurrent
Member
 
Registered: Oct 2002
Posts: 38

Original Poster
Rep: Reputation: 15
In my particular situation, the string is an entire line, so, answering my own question, the following would work:

/^STRING$/{
r FILE
d
}

Youssef Eldakar
Bibliotheca Alexandrina
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using sed to replace string in file umk Debian 12 02-01-2012 09:39 AM
c++ : replacing a char in a string cb951303 Programming 17 06-06-2005 06:48 PM
sed help, replacing a letter with a word GridX Linux - Newbie 1 09-24-2003 11:21 AM
grep - finding string and replacing with new ckibler Linux - Newbie 6 08-01-2003 07:25 PM
replacing pattern with sed produces double realos Programming 1 10-17-2002 09:03 PM


All times are GMT -5. The time now is 01:30 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration