sorry, not sure why is my previous post gone. Pls have alook at the below post:
Trying to write a script that can search for a log file which pass the two requirement and generate number of count of specific error
2 requirement - each line must be certain date, and either error1 or error2 or error3 or error4
Tried something below
my $time = localtime();
my ($wd,$mon,$mond,$times,$year) = split /\s+/, $time;
my $pattern_date = "$mon $mond";
my @array = ("error4", "error3", "error2", "error1");
my $count;
my @word_search;
my $line;
my $w;
my $wordcount;
open (OUTFILE, "/home/me/textfile.txt") || die ("can not open file for
+ writing");
while ($line = <OUTFILE>) {
chop $line;
@word_search = split(/ /,$line);
$w = 1;
while ($w <= @word_search) {
if ($word_search[$w-1] eq $pattern_date && $word_search[$w-1] eq $arra
+y[$count]) {
$wordcount++;
}
$w++;
}
}
#print ("$array[$count] occurs $wordcount\n");
#print "$pattern_date found $wordcount\n";
#}
close (OUTFILE);
And i am struck here. not sure if the split that i use really work and my "if ($word_search[$w-1] eq $pattern_date && $word_search[$w-1] eq $arr
+ay[$count]) { "
is correct. Anyone help? |