Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This should get you started, we don't know before hand whether a given line has the log entry that we need to capture but we assume that the log entries follow a certain order that may be intermittent by other uninteresting log entries (i.e each new log record starts with the 'System' entry). In the code below I am capturing the server name, the bytes in and the bytes out into a hash of incremental records, you can extend on that to capture the rest of the entries you seek..
#!/usr/local/bin/perl use strict; use warnings; use Data::Dump qw(pp); my %log; my $record = 0; #to be incremented on each round while(my $line = <DATA>){ chomp $line; my ($system,$server,$b_in,$byteIn,$b_out, $byteOut); if($line =~ /System/){ $record++ ; ($system,$server) = split / : /,$line; push @{$log{'record'.$record}},{$system=>$server} }elsif($line =~ /ByteIn/){ ($b_in, $byteIn) = split / : /,$line; push @{$log{'record'.$record}},{$b_in=>$byteIn +} ; }elsif($line =~ /Byteout/){ ($b_out, $byteOut) = split / : /,$line +; push @{$log{'record'.$record}},{$b_out +=>$byteOut} } } print pp \%log; __DATA__ System : system001-server Box : HW a2b 1234Mb 123.4, address is 0012.d345.1234 (abc 0012.d123 +. +4567) Byteout : 5816943852464 ByteIn : 4 Description : example_system_server1_example System : system002-server Box : HW a2b 1234Mb 123.4, ByteIn : 3385 Byteout : 58169 Description : example_system_server2_example
{ record1 => [ { System => "system001-server" }, { Byteout => "5816943852464" }, { ByteIn => 4 }, ], record2 => [ { System => "system002-server" }, { ByteIn => 3385 }, { Byteout => 58169 }, ], }
read Data::Dump, Data Structures Cookbook (perldsc), perlref

Excellence is an Endeavor of Persistence. A Year-Old Monk :D .

In reply to Re: Perl: Extracting specific text from a .txt file and outputting into a new format by biohisham
in thread Perl: Extracting specific text from a .txt file and outputting into a new format by ragingwhisky

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (8)
    As of 2017-11-23 10:08 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (333 votes). Check out past polls.