The output was as follows:#!/usr/bin/perl -w foreach (<DATA>) { next if /^#/; # Oops! Forgot this the first time :( my @results = split; $type = $1 if $results[3] =~ /(\.\w+)$/; $code = $results[4]; $output{$type}{$code}++; } foreach $type_key (keys %output) { foreach $code_key (keys %{$output{$type_key}}) { print "$type_key\t$code_key\t$output{$type_key}{$code_key}\n"; } } __DATA__ 00:00:29 192.168.20.50 GET /Plastic/ProductTop.html 200 00:00:29 192.168.20.50 GET /Plastic/images/ProductNavTopRt.jpg 304 00:00:29 192.168.20.50 GET /plastic/ProductNav.html 200 00:00:29 192.168.20.50 GET /plastic/images/ProductNav1b.jpg 304 00:00:29 192.168.20.50 GET /main.html 202
Cheers,.html 200 2 .html 202 1 .jpg 304 2
Update: I'm seeing responses to this node which are almost, but not quite correct. If you read the question carefully, you'll notice that the type and code are not synonymous. You can't just lump them together and ++, nor can you simply count the instances of each type. Each type can have multiple codes and it's the instances of each code per type that the poster as looking for.
In reply to Re: Parsing a log file
by Ovid
in thread Parsing a log file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |