[boulder.pm] FW: text extract

Chip Atkinson chip at rmpg.org
Wed Jul 25 17:50:23 CDT 2001


While perhaps not the best way, here's a way at least

$start_looking = 0;

while (<>)
{
   if (/2a/)
   {
     $start_looking = 1;
     next;
   }

   if ($start_looking && /NEEDLE/)
   {
     print ("Found it\n");
     exit;
   }
}

Another possibility is to read in the entire file in slurp mode and look
for a pattern like /2a.*NEEDLE.*/.

Chip

On Wed, 25 Jul 2001, Justin Crawford wrote:

> Whoa, got ahead of myself there...
> 
> I'm trying to extract multiple lines of data from a text file, only if one
> of the lines contains a string.  Picture a file like so:
> 
> 1a
> haystack
> haystack
> haystack
> haystack
> 1b
> 
> 2a
> haystack
> haystack
> NEEDLE!!!
> haystack
> 2b
> 
> I want to cruise the text file getting every chunk that's like the one from
> 2a to 2b.
> 
> What's the best way?
> 
> Thanks!
> 
> Justin Crawford
> Oracle DBA Team
> University of Colorado Management Systems
> 303-492-9083
> 




More information about the Boulder-pm mailing list