
asandybox
Novice
Jun 19, 2012, 8:00 AM
Views: 7691
|
|
Re: [rovf] Stuck on how to iterate a list in a file against a logfile.
|
|
|
Thanks rovf, here is my attempt at combining your code:
#!/usr/bin/perl use warnings; use strict; my $file = "ip.txt"; open (FH, "< $file") or die "Can't open $file for read: $!"; my @lines=<FH>; close FH or die "Cannot close $file: $!"; my $regexp='\\b('.join '|',(map { quotemeta($_) } @lines).')\\b'; while (<>) { for my $line (@lines){ #if ($_ =~ m/.*$line.*/g) { if ($_ =~ m/$regexp/g) { print $_; } } } Still no luck. So what I am getting is the regex is the issue. I still don't get why something like: if ($_ =~ m/.*$line.*/g) Won't just print any lines with an IP followed by anything around it?
(This post was edited by asandybox on Jun 19, 2012, 8:12 AM)
|