Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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_exam +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......... ==

Replies are listed 'Best First'.
Re: Perl: Extracting specific text from a .txt file and outputting into a new format
by fisher (Priest) on Nov 18, 2010 at 10:30 UTC
    There is not enough information, may I say
    Is these strings from log file have static positions? Is the system name have some pattern to find it out from log file?
Re: Perl: Extracting specific text from a .txt file and outputting into a new format
by Anonymous Monk on Nov 18, 2010 at 11:14 UTC