Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regex to extract certain lines only from command output/text file.

by Kenosis (Priest)
on Mar 08, 2013 at 00:57 UTC ( #1022323=note: print w/ replies, xml ) Need Help??


in reply to Regex to extract certain lines only from command output/text file.

Perhaps the following will be helpful:

use strict; use warnings; local $/; my @record; for ( split /(.+Generic.+)/m, <> ) { next unless /\S/; s/\n+$//g; push @record, $_; if ( @record == 2 ) { $record[1] =~ s/(\n?.+?Generic\n)/print $1; ''/ge; print "@record\n" if "$record[0]$record[1]" =~ /---/; undef @record; } }

Output on your data set:

7 hostname12 Generic-legacy 10000000AB210ACF6 --- 10000000AB210ACF4 2:5:4 10000000AB210ACF4 2:3:4 10000000AB210ACF6 3:5:4 20 hostname14 Generic-legacy 10000000AB2A3000C --- 10000000AB2A3000E 3:3:1 21 HOSTNAME Generic 23 srvernam Generic-legacy 5001438002A3004A 3:3:3 5001438002A3004A --- 5001438002A30048 2:3:3 5001438002A30048 2:5:2 5001438002A30048 2:5:2

Usage: perl script.pl inFile [>outFile]


Comment on Re: Regex to extract certain lines only from command output/text file.
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1022323]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-09-22 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls