Re: Grep through a log file
- From: mlist@xxxxxxxxxxx (Mlist)
- Date: Thu, 09 Nov 2006 10:14:26 -0700
Matt,
A couple of things here. first, you don't perform any modification of
$culist, but the strings in $culist don't appear unmodified in the log
file. the string perl reads into $_ from a file like you're example is
e.g. "SUN9-GT:\n". The string in the log file, though, is just
"SUN9-GT". try something like '$culist =~ tr/:\n//' or
while (my $culist = <CULIST>) {
chomp $culist;
$culist =~ s/(\w+):/$1/;
# .... the rest of your code
}
Next, grep(). grep takes a list and returns the elements of the list
that match. the 'while (<>)' construct, though, only reads a line at
time, and you don't seem to be splitting into an array. That makes
grep superfluous. All you need here is:
while (<SEPTEMBER>) {
chomp;
print CU_OUTPUT "$_\n\n" if /$culist/;
print "$_\n\n";
}
HTH,
-- jay
First, thanks for your input Jay, Rob, Lawrence
Jay,
I tried your script. What happens is it gets through the first
iteration of the script and copies the appropriate lines to the new log
file. But each subsequent iteration is skipped over.
This is what I have:
use warnings;
use strict;
open CULIST, "/root/syslog_stuff/CULIST3.txt" or die $!;
open SEPTEMBER, "/var/log/log_netscreen_sep" or die $!;
while (<CULIST>) {
chomp (my $culist = $_);
print "$culist\n";
open CU_OUTPUT,">> /root/syslog_stuff/monthly_logs/sep2/$culist"or die
$!;
while (<SEPTEMBER>) {
chomp;
print CU_OUTPUT "$_\n\n" if /$culist/;
# print "$_\n\n";
}
}
The script goes through each $culist (shown by printing the each
variable) - but it looks like it's skipping over the "while
(<SEPTEMBER>)" part for the rest of the $culist. Any ideas?
Matt
.
- Follow-Ups:
- Re: Grep through a log file
- From: nobull67@xxxxxxxxx
- Re: Grep through a log file
- From: Jay Savage
- Re: Grep through a log file
- References:
- Grep through a log file
- From: Mlist
- Re: Grep through a log file
- From: Jay Savage
- Grep through a log file
- Prev by Date: Extract data from binary file
- Next by Date: Re: Complicated sort
- Previous by thread: Re: Grep through a log file
- Next by thread: Re: Grep through a log file
- Index(es):
Relevant Pages
|