Q:

Bash replace line in a file with multiline file

I have a text file which has some place holder values:
Example:
Parent:
   Child: x
   Child2: <place-holder>

Car:
   Seat: x
   Door: <place-holder>

I am accomplishing this with sed in a way that works on both MacOS and Linux
sed -i .bak "s/<place-holder>/$REPLACEMNET_VALUE/g" file.yml

What I need to accomplish now is one step further, to inject a section in this file. 
I have a file with several lines in the proper format and the location of that file in an environment variable.
sed -i .bak "s/<place-holder-section>/$(<$CONFIG_OPTIONS_TEMP)/g" config.yml

However, sed seems to not be able to handle multiple lines (without escaping).
Error:
sed: 1: "s/<place-holder-section>/ f ...": unescaped newline inside substitute pattern

This could probably be solved with some looping and grepping for the line position and such but I am hoping maybe someone has a more elegant solution, possibly using awk? Keeping MacOS cross-compatibility is a concern as well.

A:

Sed has another command 'r filename' "append text read from filename".  So if all the text to be inserted is in a file by itself, you could use this sed command.
Example:
bjb@blueeyes:~$ cat /tmp/old
Parent:
  Child: x
  Child2: <place-holder>

Car:
  Seat: x
  Door: <place-holder2>

<foo>

bjb@blueeyes:~$ cat /tmp/new
CarSeat:
    padding: fluff
    belt:  seat-belt-stuff

bjb@blueeyes:~$ sed '/<foo>/ {
> x
> r /tmp/new
> }' /tmp/old
Parent:
  Child: x
  Child2: <place-holder>

Car:
  Seat: x
  Door: <place-holder2>

CarSeat:
    padding: fluff
    belt:  seat-belt-stuff

bjb@blueeyes:~$ 

The sed command is addressed to the marker  in file /tmp/old - it puts that line in the hold space and never retrieves it so it has the effect of replacing the marker  with the contents of the file /tmp/new.

