Question about multiline replacement Sed

I have a problem replacing sed, and I hope one of you can help me. I am sure that I am missing something simple.

So, I have a file containing text and a quote. The quote itself can be on the same line or span multiple lines. I need a quote on a new line. An example file is shown.

And he said "This too
   shall pass"

I need to change this to

And he said 
"This too shall pass"

I tried the next saddle, but it didn’t work - everything seems to be in order, but failed to create a new line

/"This/ {
    N
    s/"This *\n*too *\n*shall *\n*pass"/\n"This too shall pass"/
}
+3
source share
3 answers

Try replacing "\ n" with \ and an explicit new line; as below:

/"This/ {
N
s/"This *\n*too *\n*shall *\n*pass"/\
"This too shall pass"/
}
+3
source

, ", tr ( tr)

$ sed -e :a -e '$!N; s/\n/ /; ta ; s/"/\n"/' multiline_input | tr -s " "
And he said 
"This too shall pass"
+2
perl -0777 -ne 's/\s+/ /g;s/"/\n"/;print "$_\n"'
+2

All Articles