note
merlyn
<blockquote><code>
cat /var/log/httpd/access_log | perl -l -a -n -e 'print $F[6]' | sort | uniq -c | sort -n | tail -10
</code></blockquote>
Hmm. A [http://www.ling.helsinki.fi/~reriksso/unix/award.html|Useless Use of Cat], using Perl like it was awk, and then chaining together a few other tools like forking is free. Hmm.
<p>
I'd probably have written that as:
<code>
@ARGV = qw(/var/log/httpd/access_log);
my %count;
while (<>) {
my ($f) = (split)[6];
$count{$f}++;
}
my $n = 0;
for (sort {$count{$b} <=> $count {$a}) {
print "$_\n";
last if ++$n >= 10;
}
</code>
I bet mine runs with 1/4th the CPU.
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-9073">
<p>-- [http://www.stonehenge.com/merlyn/|Randal L. Schwartz, Perl hacker]
<br>
Be sure to read [id://205373|my standard disclaimer] if this is a reply.</p>
</div></div>
440268
440268