Jamie, thanks so much for your suggestion. I had to look up the -a switch to understand how they work. I would have never thought that the solution would involve the end-of-line character, as both your and John's solution did. Thank you for teaching me that.
All three of your solutions worked 'out of the box.' The third one took significantly longer, due to the sorting involved. A significant difference between all three of your scripts and my program was that IP addresses that are already resolved in the web log are skipped. Your solutions print the first field, whether or not it's an IP address or domain name. Thanks, again, for your help. -Kevin -----Original Message----- From: Jaime Murillo [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 17, 2006 4:08 PM To: beginners@perl.org Subject: Re: One liner to return unique IPs from web log? On Wednesday 17 May 2006 07:57, Zembower, Kevin wrote: > I'm trying to write a perl one-liner to return the unique IP addresses > from a Apache web log, like this: > > perl -ne 'print if s/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) .*/$1/' > access.log | nawk '!x[$0]++' > > I tried to combine it with this script to count unique entries without > sorting (which I learned from this list. Thanks!): > > perl -ne 'print unless $seen{$_}++;' > > I tried to combine them into this: > > perl -ne 'print unless $seen{s/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) > .*/$1/}++' access.log > > but it just returns the first entry of the file. I can do it like this, > but this offends me: > > perl -ne 'print if s/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) .*/$1/' > access.log | perl -ne 'print unless $seen{$_}++;' > > Any advice on correcting my script? Thanks in advance for your > suggestions. > > -Kevin Do any of these work for you perl -ane '$ip=shift @F; print $ip, "\n" unless $seen{$ip}++;' /var/log/httpd-access.log perl -ane 'print $F[0], "\n" unless $seen{$F[0]}++;' /var/log/httpd-access.log perl -ane '$seen{shift @F}++;} {print join("\n",sort keys %seen),"\n";' /var/log/httpd-access.log work for you? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>