I have a shell script in which I want do replace a multi line pattern by the text inside a variable using sed (not awk or perl or any other stuff) such that
Code:
...
<!-- ontag -->
foo
bar
foobar
<!-- offtag -->
...
(Yes, it's in an html file)
becomes
Code:
...
<!-- ontag -->
new
multi
line
pattern
<!-- offtag -->
...
What I have so far is:
Code:
FILE="/my/file/name"
ANYVAR="<!-- ontag -->\nnew\nmulti\nline\npattern\n<!-- offtag -->"
sed ':a $!{N;ba}; s/<!-- ontag -->.*<!-- offtag -->/'"${ANYVAR}"'/g' -i $FILE
But this just produces:
(It only prints the name of the variable instead of the content)
If I directly insert the pattern instead of a variable like:
Code:
sed ':a $!{N;ba}; s/<!-- ontag -->.*<!-- offtag -->/<!-- ontag -->\nmulti\nline\npattern\n<!-- offtag -->/g' -i $FILE
everything works fine so it seems as if it is just the way I access the variable.