Craig Sharp wrote: > Hi all, > > I know this is simple but I have having a brain lock today. > > I have a file in which I need to find a particular line. Once I find the > line, I need to print the next 5 lines and quit. > > The following gets me to the line but I am stuck from there. > > #!/usr/bin/perl -w > > open (INFILE,"filemon2005012970.out") || die("Cannot open file: $!"); > > @LINES = <INFILE>; > > foreach (@LINES){ > chomp; > if (/\/dev\/hdisk18 description:/){ > print "$_\n"; > } > }
Example using this script file : # fubar open IN, $0 or die "Cannot open file: $!"; my @lines = <IN>; for (my $ii = 0; $ii < @lines; $ii++) { if ($lines[$ii] =~ /^# fubar/){ print "Found: $_"; print @lines[$ii+1 .. $ii+5]; last; } } close IN; __END__ -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Unix-Users mailing list Perl-Unix-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs