This demonstrates how to parse such a file and extract the relevant info with regexes. You may tweak those to match the fields you want.
use strict; use warnings; use Data::Dumper; my ($mac, %data); while ( <DATA> ) { if ( /^Ethernet address: ([0-9a-f]{12}) \(([^\)]+)/ ) { $mac = $1; $data{$mac}{device} = $2; next; } if ( /(Incoming|Outgoing) total ([0-9]+) packets/ ) { $data{$mac}{$1} = $2; next; } if ( /Average rates: ([0-9\.]+) kbytes\/s incoming, ([0-9\.]+) kby +tes\/s outgoing/ ) { $data{$mac}{incomingRate} = $1; $data{$mac}{outgoingRate} = $2; } } print Dumper (\%data); __DATA__ Ethernet address: 009096c7cf98 (ADSL Modem) Incoming total 297089 packets, 45056408 bytes; 293887 IP packe +ts Outgoing total 401212 packets, 252051283 bytes; 398003 IP pack +ets Average rates: 0.47 kbytes/s incoming, 2.63 kbytes/s outgoing Last 5-second rates: 0.00 kbytes/s incoming, 0.00 kbytes/s out +going Ethernet address: 0020ed7924c2 (Debian Router ext) Incoming total 401212 packets, 252051283 bytes; 398003 IP pack +ets Outgoing total 297096 packets, 45056702 bytes; 293887 IP packe +ts Average rates: 2.63 kbytes/s incoming, 0.47 kbytes/s outgoing Last 5-second rates: 0.00 kbytes/s incoming, 0.00 kbytes/s out +going
Output:
$VAR1 = { '009096c7cf98' => { 'outgoingRate' => '2.63', 'incomingRate' => '0.47', 'Outgoing' => '401212', 'Incoming' => '297089', 'device' => 'ADSL Modem' }, '0020ed7924c2' => { 'outgoingRate' => '0.47', 'incomingRate' => '2.63', 'Outgoing' => '297096', 'Incoming' => '401212', 'device' => 'Debian Router ext' } };


holli, /regexed monk/

In reply to Re: How to Process Log file by holli
in thread How to Process Log file by Anonymous Monk

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.