Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Showing results for 
Search instead for 
Did you mean: 


Occasional Visitor


Here are certain conditions I need to fulfill

1)Replace a particular filename by the contents of the file in a master file

Tried it with sed but sed cudnt know how to replace the file contents something like
XYZ=srch pattern
XYZ could be anywhere of course :)

sed 's/XYZ/`cat ABC`/g'
Peter Nikitka
Honored Contributor



you where on the right path!
The first change for a solution would be to substitue the singlequotes to double quotes:

1) sed "s/XYZ/`cat ABC`/g"

BUT: you have to keep in mind, that
a character "/" in the file content of 'ABC' will make the substitute pattern invalid because "/" is the pattern delimiter. You can use any character NOT in file ABC for this purpose, e.g.

2) sed "s§XYZ§`cat ABC`§g"

There is no need for spawning an extra 'cat' process in posix shells, use

3) sed "s/XYZ/$(
Take extra care when ABC contains newlines.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Honored Contributor


My two cents using ex(1) though I prefer Peter's solution:

# ex -s +"/XYZ/r ABC | /XYZ/d | x" file
James R. Ferguson
Acclaimed Contributor



# perl -pe 'if (s/XYZ//) {chomp;open(FH,"<","XYZ") or die;@a=;print @a}' ABC


Frank de Vries
Respected Contributor



export FILE=/path/nameofyourfile

sed "s!XYZ!$(<$FILE)!g"

When using " " quotes you can
embedd variables.
Look before you leap
Frank de Vries
Respected Contributor


How many points should I assign to replies?
Every response to your question is eligible to earn between 1-10 points. No need to worry about running out of points - when a truly awesome reply rolls in that deserves a 10, you will be able to assign it a 10! However, be careful to assign points based on the value that a reply truly provides. Use the following scale as a guideline:

o N/A: The answer was simply a point of clarification to my original question

o 1-3: The answer didn't really help answer my question, but thanks for your assistance!

o 4- 7: The answer helped with a portion of my question, but I still need some additional help!

o 8-10: The answer has solved my problem completely! Now I'm a happy camper!

Although assigning points is not mandatory, it is a key component of a strong, interactive community, and it is STRONGLY ENCOURAGED. Others have taken time to help you, so please take a moment to give them credit for their assistance!
Look before you leap