RE: matching elements from array and print the results line by line from log file
- From: acravens@xxxxxxx (Andy Cravens)
- Date: Tue, 28 Oct 2008 15:51:53 -0600
-----Original Message-----
From: slow_leaner [mailto:mmlkkl6768@xxxxxxxxx]
Sent: Tue 10/28/2008 11:58 AM
To: beginners@xxxxxxxx
Subject: matching elements from array and print the results line by line from log file
Hi,
I have a list of element in array that I would like to match the
pattern in logs file. I have hard time take element from array and
matching it. More then weeks now and don't know where to find in man
page. please help me. Here is my code.
#!/usr/bin/perl -w
open ( FILE, " /var/log/cisco.log " ) || die "can't open cisco.log
file!";
@cisco.log = <FILE>;
close (FILE);
@array = qw( BPDUGUARD FAN_FAIL ); # more then 2 elements in array
while (<@cisco.log>){
foreach $line (@array){
$_ =~ $line; #DOESN'T WORK AND I AM STUCK..
print "$_\n"; #WANT TO PRINT THAT MATCH
}
}
__END__
thanks for your help
--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/
Try this and let me know if it works...
#!/usr/bin/perl -w
open ( FILE, "/var/log/cisco.log " ) || die "can't open cisco.log file!";
@cisco = <FILE>;
close (FILE);
@array = qw( BPDUGUARD FAN_FAIL ); # more then 2 elements in array
foreach $line (@cisco) {
foreach $string (@array) {
if ($line =~ $string) { print "$line $string"; }
}
}
exit;
- Follow-Ups:
- References:
- Prev by Date: Can't download and install Spread***::WriteExcel module on WindowsXP
- Next by Date: Re: matching elements from array and print the results line by line from log file
- Previous by thread: matching elements from array and print the results line by line from log file
- Next by thread: Re: matching elements from array and print the results line by line from log file
- Index(es):