I'm lost trying to do following substitution with sed:
@ edit: to capture the full complexity of my problem, I added the fact that filenames are contained in variables afterwards. Solutions might therefore directly use the filenames.
given a variable I='insert.txt':
'insert.txt':
Text I wanna skip.
This is text to insert containing
spaces and new lines
given a variable M='toModify.txt':
'toModify.txt':
Insert the new text: here.
I would like to replace the 'here' from $M with the content of $I:
Insert the new text: This is text to insert containing
spaces and new lines.
I tried:
sed -e "s/here/$(tail -n2 $I | sed -e 's/ /\\ /g' | tr '\n' '\\n')/" $M
with error: sed unterminated `s' command
The problem is that I don't get the spaces and new lines without terminating the s command.
Any solution?