Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Matching a cisco interface config

by BrowserUk (Patriarch)
on Jan 12, 2010 at 09:59 UTC ( [id://816856]=note: print w/replies, xml ) Need Help??


in reply to Matching a cisco interface config

Try

#! perl -slw use strict; $/ = "!\n"; ## set the delimiter while( <DATA> ) { 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 ! 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.

Replies are listed 'Best First'.
Re^2: Matching a cisco interface config
by FloydATC (Deacon) on Jan 12, 2010 at 20:00 UTC
    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

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (8)
As of 2024-04-23 17:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found