3 Hint on using the g flag
source | link

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). And, to ensure matches on all your (\n-separated) lines are substituted, don't forget to use the g flag for global substitutions (e.g. s/.../.../g).


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

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.

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). And, to ensure matches on all your (\n-separated) lines are substituted, don't forget to use the g flag for global substitutions (e.g. s/.../.../g).


Credits: @stéphane-chazelas first mentioned -z in a comment above.

2 Add statement of caution
source | link

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.

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

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

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.

1
source | link

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

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