I want to match everything that is between some lines with regexp but not this that match the start and the end. This sound to me as positive lookbehind and positive lookahead
start text
bla bla
bla
end
There are multiple number of this kind of blocks so I would like to extract all this blocks and then for each of these blocks I would like to extract something based on a different regexp. So it should be something like:
match start
then match everything until the first occurrence of end
match start
then match everything until the first occurrence of end
and so on…
so I made something like this: (?<=start).*(?=end)
This does not work because I guess I use the command line grep, which treats the file as a set of lines and tries to apply the regex in every single line. Is there any way to treat the file as a whole line or this is not a good solution and I have to use a combination of various command line tools like extracting the text with sed and then build a file whose lines contains the concatenation of various lines from the initial file?
Best Answer
Since a'r beat me to the sed solution, I'll just post the perl equivalent:
It's a bit more verbose though.