#!/usr/bin/perl # Script to parse logfile as specified in PerlMonks node 619685 use strict; use warnings; my %log; while() { # This is the interesting line, I'll explain it below my($system, $subsystem, $message) = /(\S+)\s*\-\s*([^:]+):\s*(.+)/; $log{$system}{$subsystem}{$message}++; } foreach my $system (sort keys %log) { print "$system:\n"; foreach my $subsystem (sort keys %{$log{$system}}) { print "\t$subsystem\n"; foreach my $message (sort keys %{$log{$system}{$subsystem}}) { print "\t\t($log{$system}{$subsystem}{$message}) $message\n"; } } print "\n"; } __DATA__ mail2-out - ntpd: sendto(192.168.4.10): Bad file descriptor mail2-out - postfix/smtp: warning: valid_hostname: empty hostname mail2-out - postfix/smtp: warning: malformed domain name in resource data of MX record for hotmil.com: mail2-out - ntpd: sendto(192.168.4.20): Bad file descriptor mail2-out - ntpd: sendto(192.168.4.10): Bad file descriptor mail2-out - postfix/smtp[32282]: warning: numeric domain name in resource data of MX record for uyahoo.com: 10.0.0.2 mail2-out - ntpd: sendto(192.168.4.20): Bad file descriptor mail2-out - ntpd: sendto(192.168.4.10): Bad file descriptor infocache02 - ldap_cachemgr: libsldap: Status: 91 Mesg: openConnection: simple bind failed - Can't connect to the LDAP server infocache02 - ldap_cachemgr: Error: Unable to refresh from profile:tls_automount_profile. (error=1) infocache02 - sendmail: l560aB7V017120: Losing ./qfl560aB7V017120: savemail panic infocache02 - sendmail: l560aB7V017120: SYSERR(root): savemail: cannot save rejected email anywhere infocache02 - sendmail: l1FM2rFa026352: Losing ./qfl1FM2rFa026352: savemail panic infocache02 - sendmail: l1FM2rFa026352: SYSERR(root): savemail: cannot save rejected email anywhere infocache02 - sendmail: l1FI2rFa022597: Losing ./qfl1FI2rFa022597: savemail panic mail2-in - postfix/smtpd: warning: 190.55.102.166: hostname cpe-190-55-102-166.telecentro.com.ar verification failed: hostname nor servname provided, or not known mail2-in - postfix/smtpd: warning: 201.29.80.154: hostname 20129080154.user.veloxzone.com.br verification failed: hostname nor servname provided, or not known mail2-in - postfix/smtpd: warning: 84.9.96.201: address not listed for hostname mail.intechcentre.com mail2-in - postfix/smtpd: warning: 84.9.96.201: address not listed for hostname mail.intechcentre.com mail2-in - postfix/smtpd: warning: 190.8.87.73: hostname din-190-8-87-73.manquehue.net verification failed: hostname nor servname provided, or not known mail2-in - postfix/smtpd: warning: 190.8.87.73: hostname din-190-8-87-73.manquehue.net verification failed: hostname nor servname provided, or not known