My apologies for the 3 posts, netscape kept crashing so my last one from IE
is the newest code...

my dilemna isn't that it starts at the beginning of the line, the regex, as
it doesn,'t.

rather, how do I say

open file, read file, for every occurrence of <regex>, print that line + the
next 20 lines immediately following it and then move on until another
occurrence of <regex> is found and execute again. <regex> being SunOS,
of course.

My present code

#!/usr/local/bin/perl -w

$file="/var/adm/messages";

printf "test of the emergency broadcast system\n";

open (FILE, "< $file") or die "can't open $file: $!";
$des_line =~ /SunOS/;
do { $line = <FILE> } until $. =~ $des_line;
printf "The desired line's number is $.\n";
$des_num = ($. - 1);
printf "The number is still $des_num";
@file_lines = <FILE>;

printf $file_lines[$des_num];
for ($i = 0; $i < 20; $i++) {
printf "$file_lines[$des_num + $i]";
}

Is getting close, but now I'm not getting the first line, the "SunOS" line
in
the output but I am getting the next twenty following...

I'm also just asking for general input/advice regarding the logic. For
example,
I believe I should have a subroutine that looks for all occurrences of SunOS
(if any),
notes the line number(s) and then another subroutine that then fetches and
prints
that line plus the 20 lines following for each occurrence found.

'but'

since I can't even get this part correct I'm stuck...

many thanks!

--

John Lawrence <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> I'm no expert myself, so I can't comment on the perl, but if as you say
the
> "SunOS" is at the start of the line.
> > reboots which always start with the string SunOS and, if found, return
>
> You may want to put a ^ in your regex to fix this. So,
> >         if ($_ =~ /SunOS/)
> becomes:
> if ($_ =~ /^SunOS/)
> Otherwise it'll match if that occurs anywhere in the line. That may never
be the case, but I don't know many answers so I have to leap at anything I
do know ;)
>
> --
> John
>



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

Reply via email to