in reply to Parse log file
#!/usr/bin/perl # http://perlmonks.org/?node_id=1207042 use strict; use warnings; my (%services, %bydate); while(<DATA>) { /^(.{15}) (\S+) ([\w-]+)/ or next; $services{$3}++; $bydate{$1}{count}++; $bydate{$1}{$3}++; } my @services = reverse sort keys %services; print "Time Number_of_times_timestamp_appeared @services\n"; for my $key ( sort keys %bydate ) { print "$key $bydate{$key}{count} @{[ map $bydate{$key}{$_} // 0, @services ]}\n"; } __DATA__ Jan 7 04:13:02 centos1 rsyslogd: [origin software="rsyslogd" swVersio +n="5.8.10" x-pid="1453" x-info="http://www.rsyslog.com"] rsyslogd was + HUPed Jan 7 04:15:41 centos1 puppet-agent[5467]: Unable to fetch my node de +finition, but the agent run will continue: Jan 7 04:15:41 centos1 puppet-agent[5467]: getaddrinfo: Name or servi +ce not known Jan 7 13:16:01 centos1 puppet-agent[9305]: (/File[/var/lib/puppet/lib +]) Could not evaluate: Could not retrieve file metadata for puppet:// +puppet/plugins: getaddrinfo: Name or service not known Jan 7 13:16:02 centos1 dhclient[1624]: DHCPREQUEST on eth0 to 192.168 +.0.1 port 67 (xid=0xf27d6e5) Jan 7 13:16:15 centos1 dhclient[1624]: DHCPREQUEST on eth0 to 192.168 +.0.1 port 67 (xid=0xf27d6e5)
Outputs:
Time Number_of_times_timestamp_appeared rsyslogd puppet-agent dhclient Jan 7 04:13:02 1 1 0 0 Jan 7 04:15:41 2 0 2 0 Jan 7 13:16:01 1 0 1 0 Jan 7 13:16:02 1 0 0 1 Jan 7 13:16:15 1 0 0 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parse log file
by pr33 (Scribe) on Jan 11, 2018 at 02:51 UTC |