File 1:
<!doctype html><html lang="en"><head><meta name="REPLACE_ME"></head><body></body></html>
File 2:
<meta name="A" content="A1"><meta name="B" content="B1">
I am trying to replace the <meta name="REPLACE_ME">
in File 1
with the entire contents of File 2
.
Expected result:
<!doctype html><html lang="en"><head><meta name="A" content="A1"><meta name="B" content="B1"></head><body></body></html>
If File 1
had multiple lines I have this working with something like this:
TOKEN="<meta name=\"REPLACE_ME\">"
sed -e "/${TOKEN}/r file2" -e "/${TOKEN}/d" file1
The issue I am having is figuring out how to do this with sed
when things are NOT on separate lines in File 1
.
Have this as my last attempt:
TOKEN="<meta name=\"REPLACE_ME\">"
sed "s/${TOKEN}/$(sed -e 's/[&/]/\&/g' -e 's/$/\n/' file2 | tr -d '
')/" file1
However, is funky and uses tr
which I would like to avoid. Any help would be greatly appreciated.
question from:
https://stackoverflow.com/questions/65839929/sed-replace-token-in-a-multiline-file-with-the-contents-of-another-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…