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

comment on

( [id://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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-16 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found