Hi Monks, I seek wisdom on following question
#Write a script which parses /var/log/messages and generates a CSV wit +h two columns: minute, number_of_messages in sorted time order. #---------- begin sample output ---------- #minute, number_of_messages #Jan 20 03:25,2 #Jan 20 03:26,2 #Jan 20 03:30,2 #Jan 20 05:03,1 #Jan 20 05:20,1 #Jan 20 05:22,6 #---------- end sample output ------------"""

Associated Text file is as follows

Jan 20 03:25:08 fakehost logrotate: ALERT exited abnormally with [1] Jan 20 03:25:09 fakehost run-parts(/etc/cron.daily)[20447]: finished l +ogrotate Jan 20 03:26:21 fakehost anacron[28969]: Job 'cron.daily' terminated Jan 20 03:26:22 fakehost anacron[28969]: Normal exit (1 job run) Jan 20 03:30:01 fakehost CROND[31462]: (root) CMD (/usr/lib64/sa/sa1 1 + 1) Jan 20 03:30:01 fakehost CROND[31461]: (root) CMD (/var/system/bin/sys +-cmd -F > /dev/null 2>&1) Jan 20 05:03:03 fakehost ntpd[3705]: synchronized to time.faux.biz, st +ratum 2 Jan 20 05:20:01 fakehost rsyslogd: [origin software="rsyslogd" swVersi +on="5.8.10" x-pid="20438" x-info="http://www.rsyslog.com"] start Jan 20 05:22:04 fakehost cs3[31163]: Q: ".../bin/rsync -LD ": symlink + has no referent: "/var/syscmds/fakehost/runit_scripts/etc/runit/serv +ice/superImportantService/run"#012Q: ".../bin/rsync -LD ": rsync erro +r: some files/attrs were not transferred (see previous errors) (code +23) at main.c(1039) [sender=3.0.6] Jan 20 05:22:04 fakehost cs3[31163]: I: Last 2 quoted lines were gene +rated by "/usr/local/bin/rsync -LD --recursive --delete --password-fi +le=/var/syscmds/modules/rsync_password /var/syscmds/fakehost syscmds@ +fakehost::syscmds_rsync" Jan 20 05:22:08 fakehost cs3[31163]: Q: ".../sbin/sv restart": ok: ru +n: /export/service/cool-service: (pid 32323) 0s Jan 20 05:22:08 fakehost cs3[31163]: I: Last 1 quoted lines were gene +rated by "/sbin/sv restart /export/service/cool-service" Jan 20 05:22:09 fakehost cs3[31163]: R: cs3: The cool service on fak +ehost does not appear to be communicating with the cool service leade +r. Automating a restart of the cool service in attempt to resolve th +e communication problem. Jan 20 05:22:37 fakehost ACCT_ADD: WARNING: Manifest /var/syscmds/inpu +ts/config-general/doit.txt has been processed already, bailing
open(IN, "fixed.txt") or die "cannot open file $!"; my %hash ={}; my @arr; while(my $row =<IN>){ push @arr, unpack("x0 A12",$row ); #print unpack("x0 A12",$row ),"\n"; } $hash{$_}++ for @arr; # Adding Header my @heading = ("minute", "number of messages"); open (OUT, '>:encoding(UTF-8)', "outputfile.csv") or die $!; $csv->print ( OUT, $_ ) for @heading; $csv->print ( OUT, $_ ) for sort keys %hash; # Error's Out close OUT;
I am getting error Can't call method print on undefine value on following line : $csv->print ( OUT, $_ ) for sort keys %hash; # Error's Out Any idea. Thanks in Advance!!!

In reply to Logfile Summarize messages by time and export to CSV by kris1511

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.