sed replace with variable with multiple lines

Viewed 11374

I am trying to replace a word with a text which spans multiple lines. I know that I can simply use the newline character \n to solve this problem, but I want to keep the string "clean" of any unwanted formatting.

The below example obviously does not work:

read -r -d '' TEST <<EOI
a
b
c
EOI

sed -e "s/TOREPLACE/${TEST}/" file.txt

Any ideas of how to achieve this WITHOUT modifying the part which starts with read and ends with EOI?

4 Answers
Related