2 of 3 Add statement of caution

GNU sed has a -z option that allows to use the syntax the OP attempted to apply. (man page)

Example:

$ cat alpha.txt
This is
a test
Please do not
be alarmed
$ sed -z 's/a test\nPlease do not\nbe/not a test\nBe/' -i alpha.txt
$ cat alpha.txt
This is
not a test
Be alarmed

Be aware: If you use ^ and $ they now match the beginning and end of lines delimited with a NUL character (not \n).


Credits: @stéphane-chazelas mentioned this already in a comment above.