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>


Reply via email to