#!/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; MSIE 5.5; Windows 98)""TC1=1067055_5565+067055+0+30fc+3fb5+20742d+1; PWH=m2w/./o0.Nyvo0/I..d/I./I.; Xc294&2127030&1=1059866137&13384&18337; Xc15&2127102&2=1060109088&13025&17516; Xc200&2127519&2=1060109135&13301&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);