develooper Front page | perl.beginners | Postings from February 2002

Re: Printing lines after a designed matching line!

Thread Previous
From:
John W. Krahn
Date:
February 27, 2002 12:37
Subject:
Re: Printing lines after a designed matching line!
Message ID:
3C7D439C.E35B00FA@acm.org
Thuy Tran wrote:
> 
> Hi all,

Hello,

> I would like to prints a specified number of lines from a file that after
> any line match a specified regular expression (ex. UID)
> 
> open(FILE, 'data' ) or die "can't open";
> if start ! = UID
>  skip line;
> else
>   read 100 lines below UID
> end if
> 
> __data__
> Nov 2002  Page 1
> 
> UID       CPU_PRIME         #SESSION
> 0              2                        0
> 1              3                        0
> ......


open FILE, 'data' or die "can't open 'data': $!";

my ( $start, $end );
while ( <FILE> ) {
    $start = $. + 1, $end = $. + 101 if /UID/;
    print if $. == $start .. $. == $end;       
    }



John
-- 
use Perl;
program
fulfillment

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About