Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 05-29-2003, 03:33 AM   #1
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
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
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:


Youssef Eldakar
Bibliotheca Alexandrina


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
c++ : replacing a char in a string cb951303 Programming 20 02-25-2015 09:18 PM
Problem using sed to replace string in file umk Debian 12 02-01-2012 09:39 AM
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 09:05 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