dear monks, i have a need to grab repeating blocks of slightly variating data but within non-variating begin and end delimiters. Here is an example:
# contents of file: ! blah ! blah blah ! # start to grab section here with start (/interface/) interface GigabitEthernet1/1/2 description PC Trunk switchport trunk encapsulation dot1q switchport trunk native vlan 100 switchport mode trunk queue-set 2 priority-queue out mls qos trust dscp storm-control broadcast level 1.00 storm-control multicast level 1.00 spanning-tree guard loop channel-protocol lacp channel-group 1 mode active ! # ^ end section with (/!/) # ignore entire block of data when after (/interface/) a (/shutdown/) +is seen before (/!/)" interface GigabitEthernet1/1/3 shutdown ! interface GigabitEthernet1/1/4 shutdown ! interface TenGigabitEthernet1/1/1 ! interface TenGigabitEthernet1/1/2 #*** Begin of sad attempt PL *** #!/usr/bin/perl -w # use strict; use warnings; my $CONFIGFILE = $ARGV[0]; print "$CONFIGFILE\n"; open(FILE, $CONFIGFILE) || die "file not found\n"; while (<FILE>) { if ($_ =~/^interface/../shutdown/) { next; } if ($_ =~/^interface/../!/) { print $_; } }
sadly the above produces no output. Can you help please? Thank you - GT
In reply to Parsing out mulitiple blocks of interesting data in files / ignoring other contents by GeorgMN
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |