Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Matching a cisco interface config

by rubasov (Friar)
on Jan 12, 2010 at 11:55 UTC ( #816881=note: print w/ replies, xml ) Need Help??


in reply to Matching a cisco interface config

If you want to keep the regex based approach try the code below, and see 'perldoc perlre' for the meaning of /m and /s modifiers. (However I think BrowserUK's solution above is more lightweigth than this.)

#! /usr/bin/perl use strict; use warnings; my $config = do { local $/; <DATA> }; my @interfaces = ( $config =~ m/^interface.+?\n!\n/msgi ); foreach my $interface (@interfaces) { print $interface, "--\n"; } __DATA__ interface GigabitEthernet6/10 description TRUNK-KBV-SW001 switchport trunk encapsulation dot1q switchport trunk allowed vlan 1,30,31,45,156-158 switchport mode trunk switchport nonegotiate ! interface GigabitEthernet6/11 description Offices switchport access vlan 31 spanning-tree portfast ! interface GigabitEthernet6/12 !


Comment on Re: Matching a cisco interface config
Download Code
Re^2: Matching a cisco interface config
by FloydATC (Chaplain) on Jan 12, 2010 at 19:52 UTC
    I knew I was missing something, and the /s modifier was it, thank you!

    -- Time flies when you don't know what you're doing

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-11-21 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (117 votes), past polls