On 7.11.2010, at 18.37, Ralf Hildebrandt wrote: > * Timo Sirainen <t...@iki.fi>: > >>> postamt:~# /var/admhome/hildeb/logparse.pl /var/log/pop3d-imapd.log >>> type >> >> Probably your timestamps are different. Show one log line? > > Nov 7 19:37:17 postamt dovecot: imap(ptm-aus): Debug: rusage: real=0.51 > user=0.16001 sys=0.52003 reclaims=665 faults=0 swaps=0 bin=0 bout=0 signals=0 > volcs=10 involcs=8
Attached with a working regexp.
#!/usr/bin/env perl use strict; my @keys; my %types; my $setkeys = 1; while (<>) { next if (!/^... + \d+ \d+:\d+:\d+ \w+ dovecot: (\w+)(\([^\)]*\))?: Debug: rusage: (.*)$/); my ($type, $data) = ($1, $3); my @new; my @list = split(" ", $data); foreach my $arg (@list) { die "broken: $arg" if ($arg !~ /^(.*)=([\d+.]+)$/); if ($setkeys) { push @keys, $1; } push @new, $2; } $setkeys = 0; if (!defined($types{$type})) { $types{$type} = \...@new; } else { my @old = @{$types{$type}}; for (my $i = 0; $i < scalar @old; $i++) { $old[$i] += $new[$i]; } } } print "type"; foreach my $key (@keys) { print "\t$key"; } print "\n"; foreach my $type (keys %types) { print "$type"; my @values = @{$types{$type}}; for (my $i = 0; $i < scalar @values; $i++) { print "\t"; if ($i < 3) { printf "%.2f", $values[$i]; } else { print $values[$i]; } } print "\n"; }