#!/usr/bin/perl -w use strict; #use File::Basename; my $workfile="/tmp/access_log.ends.01May05"; my $workdir="/tmp"; my $aliases="/tmp/aliases"; my $logname="$workdir/log"; # create a hash of {alias => destination log filename} my %a; open AL, "<$aliases" or die "can't open $aliases\n"; while() { my $alias = (split /\s+/)[1]; ($a{$alias} = $alias) =~ tr [/] [_]; } close AL; $a{"catchall"} = "_catchall"; # open a filehandle to each log destination my %fh; foreach my $k (keys %a) { my $f = "$logname".$a{$k}; open $fh{$k}, ">$f" or die "cannot open $f: $!\n"; } while() { my $line = $_; my $url = (split(/\s+/, $line))[6]; # chop off a component of the url until we find an alias match until( "/" eq $url ) { # slightly faster than File::Basename::dirname() my @tmp = split /\//, $url; pop @tmp; $url = join("/", @tmp) || "/"; if( $url ne "/" ) { if(grep(/^$url$/, keys %a) == 1) { select $fh{$url}; print $line; last; } # lines with no alias go in the catchall log } else { select $fh{"catchall"}; print $line; } } } # close all of our filehandles map { close $_ } %fh;