#!/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

In reply to Re: Parse log file by tybalt89
in thread Parse log file by pr33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.