habel_k has asked for the wisdom of the Perl Monks concerning the following question:
eg of an entry:
My code:10.25.95.100 ab - [05/Aug/2003:12:00:30 -0700] "GET /creative/2|212727 +4-1;iframe? HTTP/1.1" 200 791
#!/usr/bin/perl -w use strict; my $s = '10.25.95.100 ab - [05/Aug/2003:12:00:30 -0700] "GET /creative +/2|2127274-1;iframe? HTTP/1.1" 200 791 "-" "Mozilla/4.0(compatible; M +SIE 5.5; Windows 98)""TC1=1067055_5565+067055+0+30fc+3fb5+20742d+1; P +WH=m2w/./o0.Nyvo0/I..d/I./I.; Xc294&2127030&1=1059866137&13384&18337; + Xc15&2127102&2=1060109088&13025&17516; Xc200&2127519&2=1060109135&13 +301&18215" "Imp: 294&18421&2127274&1&13384&1060110030" -'; my $LOG_PATTERN = q{(.*) \- \[(.*)\] \"(.*) (.*)\?(.*) HTTP\/(.*)\" ([ +0-9]*) ([0-9]*)}; print "\$s=$s\n"; my $var10=''; $s =~ /(.*) \- \[(.*)\] \"(.*) (.*)\?(.*) HTTP\/(.*)\" ([0-9]*) ([0-9] +*) \"(.*)\" \"(.*)\"/; print "Trick 1: \$1=$1, \$2=$2, \$3=$3, \$4=$4, \$5=$5, \$6=$6, \$7=$7 +, \$8=$8, \$9=$9, \n", " \$\`=",$`," \$\'=",$',"\n"; my $len = @ARGV; if ($len <1){ print "Usage : perl script_name logfile\n"; exit(); } if (!(-e $ARGV[0])){ print $ARGV[0]," : not exists.\n"; exit(); } open (SEM, "< $ARGV[0]") or die "Cannot open file $ARGV[0]\n"; while () { if (my($ip,$date,$method,$url,$query,$protocol,$retcode,$byte)=($_ =~ +m/$LOG_PATTERN)) { print "IP :",$ip,"\n";} } close(SEM);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: search pattern not terminated
by GrandFather (Saint) on Jan 21, 2008 at 23:59 UTC | |
by habel_k (Initiate) on Jan 22, 2008 at 00:17 UTC | |
by GrandFather (Saint) on Jan 22, 2008 at 00:37 UTC | |
by habel_k (Initiate) on Jan 22, 2008 at 02:46 UTC | |
by olus (Curate) on Jan 22, 2008 at 00:33 UTC | |
|
Re: search pattern not terminated
by ww (Archbishop) on Jan 22, 2008 at 02:32 UTC | |
|
Re: search pattern not terminated
by ww (Archbishop) on Jan 21, 2008 at 23:55 UTC | |
|
Re: search pattern not terminated
by poolpi (Hermit) on Jan 22, 2008 at 08:11 UTC |