I have a file sample.txt
like this:
lots of text
lots of text
#nvram = [
# these
# could
# be,
# anything
#]
lots of text
lots of text
and I want to add some text "foobar" to get this:
lots of text
lots of text
#nvram = [
# these
# could
# be,
# anything
#]
foobar
lots of text
lots of text
I have looked at some related threads and tried a bunch of stuff but have not been able to join the information together in the correct way.
multiline matching: How can I use sed or ex to replace a block (multi-line code) with new block of text (code)? https://stackoverflow.com/questions/11234001/replace-multiple-lines-using-sed How can I use sed to replace a multi-line string?
appending: How to add a new line after the "test message1" using sed?
I've been trying stuff like this:
sed '/^#nvram = \[$/{
N
^.*$
}/abc123/' sample.txt
sed '/^#nvram = \[$/ {N; s/\<^#nvram = \[$\>\n<^.*$\>/abc123/g}' sample.txt
sed '/^#nvram = \[$/ {N; s/\<#nvram = \[\>\n\<.*\>/abc123/g}' sample.txt
sed '/^#nvram = \[$/ {N; s/#nvram = \[\n.*/abc123/g}' sample.txt
sed '/^#nvram = \[$/ {N; /#nvram = \[\n.*/abc123/a}' sample.txt
sed '/^#nvram = \[$/ {N; /#nvram = \[(\n.*){1,}/abc123/a}' sample.txt
sed '/^#nvram = \[$/!b;n;cABC' sample.txt
sed '/^#nvram = \[$/N;cABC' sample.txt
sed '/^#nvram = \[$/N/#\]/a;cABC' sample.txt
sed '/^#nvram = \[$/,/#\]/{/^#nvram = \[$/n;/#\]/!{s/./abc/g}}' sample.txt
sed '/^#nvram = \[$/,/#\]/{/^#nvram = \[$/n;/#\]/!{/abc/a}}' sample.txt
sed '/^#nvram = \[$/,/#\]/{/^#nvram = \[$/n;/#\]/!/a abc}' sample.txt
sed '/^#nvram = \[$/,/#\]/{/^#nvram = \[$/n;/#\]/;/a abc}' sample.txt
sed '/^#nvram = \[$/,/#\]/{/^#nvram = \[$/n;/#\]/a abc}' sample.txt
But so far I have not succeeded.