Your answer has already been set using user here .
Some link
In the simplest sed call, it has one line of text in the template space, i.e. 1 line of \ n separator text with input. The only line in the pattern space does not have \ n ... That's why your regular expression cannot find anything.
You can read a few lines in the template space and manage things surprisingly well, but with more than the usual effort. Sed has a set of commands that allow this type of thing ... Here is a link to the Summary command for sed. This is the best I found and made me ride.
However, forget about the "one liner" idea when you start using sed sed commands. It is useful to lay it out as a structured program until you feel it ... It is surprisingly simple and no less unusual. You might think of it as the "assembly language" of text editing.
Summary: use sed for simple things and maybe a little more, but overall, when it goes beyond working with a single line, most people prefer something else ... I will let someone else suggest something else. I'm really not sure what the best choice would be (I would use sed, but that is because I don't know perl well enough.)
sed '/^a test$/{ $!{ N
Here it is the same script, compressed into something that is obviously harder to read and work, but some of them doubt the one-line
sed '/^a test$/{$!{N;s/^a test\nPlease do not$/not a test\nBe/;ty;P;D;:y}}' alpha.txt
Here is my cheat-sheet team
:
source share