in reply to Selecting text between given words (multi-lines (/n) and multiple occurrences)

Maybe you could use a flag to print in-between lines. Since it's a 9 meg file you may not want to slurp the whole file in, so detecting multi-line matches may be troublesome.
#!/usr/bin/perl $goprint=0; while (<>){ if ($_ =~ /^Start(.*)/){$goprint=1} if ($_ =~ /^END(.*)/){$goprint=0;next} print "$_" if $goprint == 1; }
or if you can slurp
#Here's code that finds everything #between START and END in a paragraph: undef $/; # read in whole file, not just one line while ( <> ) { while (/START(.*?)END/sgm) { # /s makes . cross line boundaries print "$1\n"; } }

Replies are listed 'Best First'.
Re: Re: Selecting text between given words (multi-lines (/n) and multiple occurrences)
by nylon (Acolyte) on Aug 29, 2003 at 08:05 UTC
    Zentare, Thanks for the help. I created a little script that works fine with your code but if I enters a begin/end-string with spaces (e.g "begin log1", "end log1") it takes the two first words (e.g begin & log1) as the begin and the end words. The use of quotation marks does not work. Thx, Firewall
      Solved the problem :-) I just used getopt with "". That works fine.

      Thx everyone,

      Nylon