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)aabbccby 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)aaIs there any reason for that or I'm missing anything? How do I correct that?
How to print a multi-line match?
command line;search;linux;ex mode;multiple lines
There's something almost perverse in doing this with ex, akin to chopping a tree with a razor blade, or drinking a bucket of water through a straw.  But if you stop and think for a few minutes about what you're doing, it's relatively straightforward:ex +'/aa\_.\{-}cc/' +'normal gny' +new +'normal P' +'%p' -scqa! fileTranslation, for the less masochistic among us:+ introduce command line statements that apply to file/aa\_.\{-}cc/ searches for the patternnormal gn marks the text just foundy yanks said textnew opens a new buffernormal P pastes the text%p prints the buffer (i.e. :p applied to the entire buffer, a.k.a. %)-scqa! runs :qa!, i.e. bails out.The same tricks, using normal <mumble> to get to normal mode commands from within ex, and pasting stuff to a scratch buffer, can be used to solve other similar quizzes, such as printing the contents of a register, and echo-ing things (hint: use redir for that one).Edit: Alternative approach, by OP:ex +'sil /aa\_.\{-}cc/norm gny' +'redi>>/dev/stdout|echon @' -scq! filePlease note that /dev/stdout is not available on all systems.