Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Update: == The log file size and contents can vary so capturing specific lines each time may not work, searching the entries only option.
System : system001-server (System name differs by number only system001..., system002..., system +003 e.t.c) Box : HW a2b 1234Mb 123.4, address is 0012.d345.1234 (abc 0012.d123 +. +4567) (Box name relatively static, capturing between the HW a2b to the brack +eted data would get everything relevant) ByteIn : 3385567095904 (ByteIn varies) Byteout : 5816943852464 (Byteout varies) Description : example_system_server_round (Description name varies, capturing the name after "Description" only +way)
== Hello, hoping someone can help. I'm looking to get a few scripts off the ground to help me with a laborious "log" culling, but my knowledge is a bit limited regarding perl and so am learning as I go. I had been experimenting with grep and while loops e.g.
while (<IN>) { if (m/Server*Example/ig) { print OUT $_, "\n"; print $_; } }
But had been falling short on how to specify each specific part. Out of all the log files I would ideally love to extract the following snippets - System, Box, ByteIn, Bytesout, Description From the log example below the data would be:
System : system001-server Box : HW a2b 1234Mb 123.4, address is 0012.d345.1234 (abc 0012.d123 +. +4567) ByteIn : 3385567095904 Byteout : 5816943852464 Description : example_system_server_example
Once the file data had been extracted from the .txt file --> output to a new CSV format file so I could read it into spreadsheets, example - System Box ByteIn Byteout Description:
system001-server,HW a2b 1234Mb 123.4, address is 0012.d345.1234 (abc 0 + +012.d123.4567),3385567095904,5816943852464,example_system_server_ex +am +ple
This would be the ideal outcome, any help in how to do this properly would be_VERY_ much appreciated. Cas.
log example (from .txt file): system001-server GigabitEthernet7/1 is up, line protocol is up (connected) HW a2b 1234Mb 123.4, address is 0012.d345.1234 (abc 0012.d123.4567) Description: example_system_server_example MTU 1234 bytes, BW 12345678 Kbit, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set Keepalive set (10 sec) Full-duplex, 1000Mb/s, media type is 10/100/1000BaseT input flow-control is off, output flow-control is on Input queue: 0/2000/249/0 (size/max/drops/flushes); Total output drops +: 9725919 5 minute input rate 1918000 bits/sec, 166 packets/sec 5 minute output rate 659000 bits/sec, 154 packets/sec 3448177417 packets input, 3385567095904 bytes, 0 no buffer Received 8858 broadcasts (285 multicasts) 4942780696 packets output, 5816943852464 bytes, 0 underrun GigabitEthernet7/2 is up, line protocol is up (connected) HW a2b......... ==

In reply to 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 about the Monastery: (2)
    As of 2018-01-24 06:06 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (255 votes). Check out past polls.