#!/usr/bin/perl
@log = <STDIN>;
$log = join '', @log;
while ($log =~ m/(\d+\.\d+\.\d+\.\d+\s)/g)
{
$ip = $1;
chomp $ip;
$count = ($log =~ s/$1/$1/g);
print "$ip $count\n";
}
$ time cat ipaddr.txt | perl count.pl > report.txt
real 4m9.138s
user 3m7.281s
sys 0m58.301s
if i were going to run this more than once, i would probably change it to your method like this
#!/usr/bin/perl
@log = <STDIN>;
$log = join '', @log;
while ($log =~ m/(\d+\.\d+\.\d+\.\d+\s)/g)
{
$ip = $1;
chomp $ip;
++ $count{$ip};
}
foreach $ip (keys %count)
{
print "$ip $count{$ip}\n";
}
$ time cat ipaddr.txt | perl hashcount.pl > report.txt
real 0m0.501s
user 0m0.433s
sys 0m0.052s
happy holidays all