On Thu, 30 Jan 2003, Rob Dixon wrote:

> Date: Thu, 30 Jan 2003 16:40:13 -0000
> From: Rob Dixon <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Re: taking lines from a file
>
> Marcelo wrote:
> > Hi everybody...
> > How I can take lines from a file like this ...
> >
> > line1=A
> > line2
> > line3
> >
> > line1=B
> > line2
> > line3
> >
> > line1=A
> > line2
> > line3
> >
> > I want to take the followin 2 lines to the line1 when line1=A and
> > write them to another file....
>
> I'm not clear exactly what your file looks like, but the following will
> output the two lines immediately following a line exactly matching
> 'line1=A'.
>
>     @ARGV = 'file.txt';
>
>     my $print;
>
>     while (<>) {
>         if ($print and $print--) { print }
>         else { $print = 2 if /^line1=A$/ }
>     }
>
>
I like that. Nice. =)

Or if there are n-number of lines below "line1=A" and each block is
_only_ ever delimited by an empty line, ie:

   .
   .
   line3

   line1=B
   .
   .

...this would work:

    @ARGV = 'file.txt';

    my $print;

    while (<>) {
        if (m/^(line1=A\n)$/.../^\n$/) { s/$1//; print;}
    }


jab


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to