On 10/5/2004 10:25 PM, Kevin Old wrote:
Hello everyone,

I'm parsing a Logwatch report I get daily from my server and have hit
a snag.  I'd like to grab everything between the "pam_unix Begin" line
and the "pam_unix End" line.

--------------------- pam_unix Begin ------------------------ sshd: Invalid Users: Unknown Account: 17 Time(s) Authentication Failures: admin (ym74043.ym.edu.tw ): 4 Time(s) root (ym74043.ym.edu.tw ): 3 Time(s) unknown (ym74043.ym.edu.tw ): 17 Time(s)
---------------------- pam_unix End -------------------------


The code I have is (assuming the entire report is in $body):

$body =~ /
                \-+\spam_unix\sBegin\s\-+
                \((.*)\s*\)  #matchline
                \-+\spam_unix\sEnd\s\-+
        /sx;


This is where the .. range operator is useful:

while (defined( my $line = <INPUT> )) {
    if ( /-+ pam_unix Begin -+/ .. /-+ pam_unix End -+/ ) {
        # between beginning and end
    }
}

See `perldoc perlop`, section "Range Operators"


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to