I was able to make the file look like the way I needed but still I am not able to parse the VMstat logs

use strict; use warnings; use Test::Parser::Vmstat; use Tie::File; my @vmstat_data; tie @vmstat_data, 'Tie::File', $ARGV[0] or die $!; `sed '/[procs|swpd]/d' $ARGV[0] > /tmp/vmstat_intermidiate`; open (my $in, '<', "/tmp/vmstat_intermidiate") or die "Can't read ol +d file: $!"; open (my $out, '>', "/tmp/vmstat_log") or die "Can't write new file: $ +!"; print $out "$vmstat_data[0]\n"; print $out "$vmstat_data[1]\n"; while( <$in> ) { print $out $_; } close $out; close $in; `rm -rf /tmp/vmstat_intermidiate`; my $parser = new Test::Parser::Vmstat or die "Couldn't create Test::Parser::Vmstat object\n"; my $logfile = '/tmp/vmstat_log'; $parser->parse($logfile) or die "Could not parse Vmstat log.\n"; print $parser->to_xml(); OUTPUT procs -----------memory---------- ---swap-- -----io---- --system-- --- +--cpu----- r b swpd free buff cache si so bi bo in cs us s +y id wa st 1 0 0 50122424 234628 9616504 0 0 0 20 2 4 +0 0 99 0 0 0 0 0 50121664 234628 9616864 0 0 0 0 7813 5956 +1 1 98 0 0 1 0 0 50122252 234628 9616864 0 0 0 190 10727 6872 + 2 1 97 0 0 0 0 0 50122092 234628 9616864 0 0 0 164 8645 6966 +1 1 98 0 0 PERL SCRIPT OUTPUT [root@r01mgt ~]# perl parse_vmstat.pl /tmp/vmstat <vmstat> </vmstat>

In reply to Re^2: Removing matched pattern except the first pattern by rahulruns
in thread Removing matched pattern except the first pattern by rahulruns

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.