Hi,

I'm trying to search a file for several matching blocks of text. A sample
of what I'm searching through is below.

What I want to do is match "##### START block #####" through to the next
"##### END block #####" and repeat that throughout the file without
matching any of the text that falls between each matched block (that is,
the "ok: some text" lines should not be matched). Here is the one-liner I'm
using:

perl -p -e '/^##### START block #####.*##### END block #####$/s' file.txt

I've tried a few variations of this but with the same result--a match is
being made from the first "##### START block #####" to the last "##### END
block #####", and everything in between... I believe that the ".*",
combined with the "s" modifier, in the regex is causing this match to be
made.

What I'm not sure how to do is tell Perl to search from START to the next
END and then start the search pattern over again with the next START-END
match.

How might I go about achieving this?

Thank you,

~ Tom

----- Example Text -----

##### START block #####
#

A block of text.

#
##### END block #####

ok: some text

##### START block #####
#

A block of text.

#
##### END block #####

ok: some text

Reply via email to