To work with multiline
in SED
using RegEx
, you should look at here.
EDIT:
In SED
command, working with NewLine is a bit different. SED
command support three patterns to manage multiline operations N
, P
and D
. To see how it works see this(Working with Multiple Lines) explaination. Here these three operations discussed.
My guess is that N
operator is the area of consideration that is missing from here. Addition of N
operator will allows to sense \n
in string.
An example from here:
Occasionally one wishes to use a new line character in a sed script.
Well, this has some subtle issues here. If one wants to search for a
new line, one has to use "\n." Here is an example where you search for
a phrase, and delete the new line character after that phrase -
joining two lines together.
(echo a;echo x;echo y) | sed '/x$/ { N s:x\n:x: }'
which generates
a xy
However, if you are inserting a new line, don't use "\n" - instead
insert a literal new line character:
(echo a;echo x;echo y) | sed 's:x:X\ :'
generates
a X
y
[^\,]*
– Sina Iravanian