Re: [Perl-unix-users] Search for a line and print the next 5 from a file

2005-01-31 Thread $Bill Luebkert
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. > > #!

Re: [Perl-unix-users] Search for a line and print the next 5 from a file

2005-01-31 Thread Martin Moss
Hi Craig, You need to use a counter. my $count =0; $count++; You will need to also check the counter on each loop iteration using 'if' 'else' and 'last' to exit the loop.. my $count=0; if ($count > 4) { last } else { $count++; } there's several ways to do this Here is one.. Incidentally, un

Re: [Perl-unix-users] Search for a line and print the next 5 from a file

2005-01-31 Thread Craig Sharp
Tim, Perfect! Thanks for the help. Craig >>> <[EMAIL PROTECTED]> 01/31/05 11:15AM >>> Try this... #!/usr/bin/perl -w open (INFILE, "< filemon2005012970.out") || die("Cannot open file: $!"); while () { chomp; if (/\/dev\/hdisk18 description:/){ for (my $x = 0; $x < 5; $x++

[Perl-unix-users] Search for a line and print the next 5 from a file

2005-01-31 Thread Craig Sharp
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,"filemon2