Re: matching elements from array and print the results line by line from log file
- From: brian54321uk@xxxxxxxxxxx (Brian)
- Date: Thu, 30 Oct 2008 12:00:43 +0000
slow_leaner wrote:
On Oct 28, 2:51 pm, acrav...@xxxxxxx (Andy Cravens) wrote:-----Original Message-----__________________
From: slow_leaner [mailto:mmlkkl6...@xxxxxxxxx]
Sent: Tue 10/28/2008 11:58 AM
To: beginn...@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-unsubscr...@xxxxxxxx
For additional commands, e-mail: beginners-h...@xxxxxxxxxxxx://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;
thanks Andy. it works. But here is my gold.
1. i have 2 logs file that i would like to appending into one big
@LOGFILE. spend 3 hours already and still......
2. lists of element in @array that will match the line in above
@LOGFILE.
3. then email it to me with the line that match (still reading the man
page.)
As you are appending 2 files to create 1:-
I'm sure something similar is available under unix, but as I use windows, I go to a DOS(Command) prompt
copy file1+file2 file3
et voila.
.
- References:
- Prev by Date: Re: regex for &
- Next by Date: RE: Hi all
- Previous by thread: Re: 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):
Relevant Pages
|