I wrote the below code, but its not matching:
open (FILE, '<', '123.log') or die "Could not open 123.log: $!";
while (<FILE>) {
#print $_ if (/^[==========]/ .. /^tests.../);
if (/^[==========]/ .. /^tests.../){
print "Line Found:".$_."\n";
}
}
close (FILE) or die "Could not close 123.log: $!";
| [reply] [d/l] |
If you want to match [==========] in a regex, you need to escape the square brackets — otherwise they form a character class.
However, this approach cannot work: you are reading the data file line-by-line, which to Perl means from one newline (\n) to the next, but a typical line of input looks like this:
< 0x00070: 2d 64 6f 77 6e 0d 0a 5b 3d 3d 3d 3d 3d 3d 3d 3d -down..
+[========
As can be seen, there are no lines which match [==========]. Likewise, the special regex character ^ matches at the beginning of a line, and neither [==========] nor tests appears at the beginning of a line.
You will need a different strategy, along the lines outlined by hippo below.
Hope that helps,
| [reply] [d/l] [select] |
I tried one more shot with the below but no luck.
open (FILE, '<', '123.log') or die "Could not 123.log: $!";
my $i=0;
while (<FILE>) {
#print $_ if (/^[==========]/ .. /^tests./);
if (/^[0-9] tests from [0-9] test cases ran/ .. /^[0-9] tests\./){
print "$i.Match Found:".$_."\n";
$i++;
}
}
Any help? | [reply] [d/l] |