in reply to Re: Matching a cisco interface config
in thread Matching a cisco interface config

This solution works, but in practice it would require some prepping of the config file, since I failed to mention it doesn't contain just the interfaces but a lot of other config settings as well. (As most Cisco configs do)

I'll see how the regex approach below works in practice on a really big collection of configs and if I get into trouble with performance then this is probably the way to go. Thanks!

-- Time flies when you don't know what you're doing
  • Comment on Re^2: Matching a cisco interface config

Replies are listed 'Best First'.
Re^3: Matching a cisco interface config
by BrowserUk (Patriarch) on Jan 12, 2010 at 21:02 UTC

    Something like this?

    #! perl -slw use strict; $/ = "!\n"; while( <DATA> ) { next unless m[^interface]; print "'$_'"; } __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 ! stuff with more stuff ! interface GigabitEthernet6/11 description Offices switchport access vlan 31 spanning-tree portfast ! thing with other things ! interface GigabitEthernet6/12 !
    Outputs:
    C:\test>junk '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 ! '

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.