CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [FishMonger] Stuck on how to iterate a list in a file against a logfile.: Edit Log



asandybox
Novice

Jun 19, 2012, 11:42 AM


Views: 8470
Re: [FishMonger] Stuck on how to iterate a list in a file against a logfile.

Thanks fishmonger, here is another wrench in the spoke. Your example goes of a single field in this case only field2.

My original plan was to just craft some type of regex to parse the entire file to see if an "ip" or "url" existed any where in the log file.

Ex:

Field 6:

http://help.example.com.org/search/sss?

What if we wanted to match those url's and they were also in ip.txt. Another concern would not being able to parse the 8th field. "DIRECT/208.82.238.129" which also contains an ip.

I attempted to modify your code below:


Code
 

#!/usr/bin/perl

use strict;
use warnings;

my %ip;
my $file = 'ip.txt';
open my $fh, '<', $file or die "failed to open '$file' $!";

while ( my $ip = <$fh> ) {
chomp $ip;
$ip{$ip}++;
}



close $fh;


while ( <> ) {
my $ip = (split(/\s+/, $_))[2];

if ( exists $ip{$ip} ) {
print;
}

my $url = (split(/\s+/, $_))[6];
#print "$url\n";

if ($url =~ /help.$ip/) {
print;
}

}


To key off some of the other fields and perhaps introduce a regex to match www.* in the log.

Any ideas?

Thanks


(This post was edited by asandybox on Jun 19, 2012, 11:48 AM)


Edit Log:
Post edited by asandybox (Novice) on Jun 19, 2012, 11:48 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives