#!/usr/bin/perl # # resort syslog output to group by host & process name # 17 April 2000 jwa # # $Id: resort,v 1.2 2001/05/04 10:10:39 jwa Exp $ # while ($line = ) { ($mo, $day, $tm, $host, $proc, @data) = split(" ", $line); ($proc, $pid) = split(/\[/, $proc); chop $pid; chop $pid; $proc =~ s/\://g; $key = "$host -- $proc"; $hash{$key} .= $line; $linecount{$key}++; } @k = keys %hash; # my highly optimized reorder algorithm. while ($k = shift @k) { push(@list, "$linecount{$k}:$k:$hash{$k}"); } @list = sort { $a <=> $b} @list; while ($l = shift @list) { ($count, $key, @data) = split(/:/, $l); $data = join(":", @data); print "==\n== $key ($count entries)\n==\n"; print $data . "\n"; }