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

Attacking this wrong? Syslog sort & extract question

Thread Next
March 17, 2002 15:26
Attacking this wrong? Syslog sort & extract question
Message ID:
I'm fairly certain I'm attacking this incorrectly, so any advice is
greatly appreciated...


I want to sort through my Solaris syslog (/var/adm/messages) looking for
any system
reboots which always start with the string SunOS and, if found, return
that line and
the next 20 lines, at least for starters.

I was going to try and catch the line # of the line that has the SunOS
in it and then
increment that by 1, print that line from the array and then increment
by 1 for 20

I scratching out something such as.....(I'm a complete newbie and I'm
banging my head
against the wall because either I'm completely attacking this with the
wrong logic and/or
I'm misinterpreting the usage of $.

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


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

open (FILE, "< $file") or die "can't open $file: $!";
@lines = <FILE>;

    foreach (@lines) {
        if ($_ =~ /SunOS/)
        printf "$_\n";      {
        for ($i = $.; $i ($. + 20);$.++)
        printf $lines[$i];

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About