in reply to greping inside a file

$cat easy.pl #!/usr/bin/perl -w use strict; my $grade = shift || die "usage:$0 <grade>\n"; # I'll just get the input from STDIN so I don't have to # worry about what the input file is. my $flag = 0; # set this to 1 when you see your grade # set it to 0 when you see END while(<>) { if ( $flag == 1 ) { print $_ if /^firstname /; print $_ if /^lastname /; print $_ if /^middlename /; $flag = 0 if /^END/; } $flag = 1 if /^profile $grade/; } $ cat easy.in profile FIRSTGRADE location here age 23 color brown sport n/a firstname Amy lastname Cako middlename M school n/a job n/a END profile SECONDGRADE location there age 24 color white sport n/a firstname James lastname Don middlename M school n/a job n/a END profile THIRDGRADE location here age 29 color brown sport n/a firstname Amy lastname Mando middlename S school n/a job n/a END $ ./easy.pl SECONDGRADE < easy.in firstname James lastname Don middlename M

Plankton: 1% Evil, 99% Hot Gas.

Replies are listed 'Best First'.
Re: Re: greping inside a file
by Anonymous Monk on Jan 19, 2004 at 21:53 UTC
    Nice one Plankton , thanks a lot