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...
In reply to Matching a cisco interface config by FloydATC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |