I've a file where I would like to extract a multiline pattern in non-greedy way (similar to this scenario) by using ex
editor.
This example works fine:
$ ex +'/aa/,/cc/p' -scq! <(echo -e "start\naa\nbb\ncc\nend")
aa
bb
cc
by extracting me pattern between aa
and cc
, but it's uses ranges.
And I would like to extend that example by introducing a multiline non-greedy pattern (\_.\{-}
), but it doesn't print for me the whole multi-line match for some reason:
$ ex +'/aa\_.\{-}cc/p' -scq! <(echo -e "start\naa\nbb\ncc\nend")
aa
Is there any reason for that or I'm missing anything? How do I correct that?
:p
only works on single lines and does not understand multiline patterns. Therefore use ranges. That's what they are for and they are non-greedy by default. (This is also the way sed works)