FloydATC has asked for the wisdom of the Perl Monks concerning the following question:
I simply want to extract each interface config (from 'interface' to '!', inclusive) as a separate string, using a regular expression. I could rewrite this to extract each line manually but it just shouldn't be necessary.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 !
This matches only the empty config, because . does not match \n#!/usr/bin/perl my @lines = <>; my $config = join('', @lines); my @interfaces = ( $config =~ m/interface.+?\n!\n/gi ); foreach my $interface (@interfaces) { print $interface . "\n"; }
How can I make my regex match whatever lines, if any, appear between the 'interface' and '!' lines? I'm ashamed to say I've been beating my head against this for several hours and nothing seems to work...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching a cisco interface config
by BrowserUk (Patriarch) on Jan 12, 2010 at 09:59 UTC | |
by FloydATC (Deacon) on Jan 12, 2010 at 20:00 UTC | |
by BrowserUk (Patriarch) on Jan 12, 2010 at 21:02 UTC | |
|
Re: Matching a cisco interface config
by rubasov (Friar) on Jan 12, 2010 at 11:55 UTC | |
by FloydATC (Deacon) on Jan 12, 2010 at 19:52 UTC |