in reply to Re: Parsing out mulitiple blocks of interesting data in files / ignoring other contents
in thread Parsing out mulitiple blocks of interesting data in files / ignoring other contents
Hi Athanasius, Sadly the code does not seem not work the way i hoped. Can you help me out further?
#!/usr/bin/perl -w # use strict; use warnings; my $CONFIGFILE = $ARGV[0]; open(FILE, $CONFIGFILE) || die "file not found\n"; my @block; my $in_block = 0; while (<FILE>) { if (/^interface/) { push @block, $_; $in_block = 1; } elsif ($in_block) { if (/^!/) { print for (@block, $_); @block = (); $in_block = 0; } else { push @block, $_; } } } ######### OUTPUT OF SCRIPT ############ interface Port-channel1 description HIS51-10 switchport trunk encapsulation dot1q switchport trunk native vlan 100 switchport mode trunk storm-control broadcast level 1.00 storm-control multicast level 1.00 spanning-tree guard loop ! interface FastEthernet0 no ip address shutdown ! interface GigabitEthernet1/0/1 switchport access vlan 100 shutdown spanning-tree portfast ! interface GigabitEthernet1/0/2 description Internet Swisscom switchport access vlan 100 speed 1000 duplex full ! interface GigabitEthernet1/0/3 shutdown ! interface GigabitEthernet1/0/4 shutdown ! interface GigabitEthernet1/0/5 shutdown ! interface GigabitEthernet1/0/6 shutdown ! interface GigabitEthernet1/0/7 shutdown ! interface GigabitEthernet1/0/8 shutdown ! interface GigabitEthernet1/0/9 shutdown ! interface GigabitEthernet1/0/10 shutdown ! interface GigabitEthernet1/0/11 shutdown ! interface GigabitEthernet1/0/12 description A-CHHER-IF01-1 /4 switchport access vlan 100 spanning-tree portfast ! interface GigabitEthernet1/0/13 shutdown ! interface GigabitEthernet1/0/14 description A-CHHER-IF01-2 /4 switchport access vlan 100 ! interface GigabitEthernet1/0/15 shutdown ! interface GigabitEthernet1/0/16 shutdown ! interface GigabitEthernet1/0/17 shutdown ! interface GigabitEthernet1/0/18 shutdown ! interface GigabitEthernet1/0/19 shutdown ! interface GigabitEthernet1/0/20 switchport trunk encapsulation dot1q switchport trunk native vlan 100 switchport mode trunk shutdown ! interface GigabitEthernet1/0/21 shutdown ! interface GigabitEthernet1/0/22 shutdown ! interface GigabitEthernet1/0/23 shutdown ! interface GigabitEthernet1/0/24 shutdown ! interface GigabitEthernet1/1/1 description HIS51-10 G1/1/1 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 ! interface GigabitEthernet1/1/2 description HIS51-10 G1/1/2 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 ! interface GigabitEthernet1/1/3 shutdown ! interface GigabitEthernet1/1/4 shutdown ! interface TenGigabitEthernet1/1/1 ! interface TenGigabitEthernet1/1/2 ! interface Vlan1 no ip address no ip route-cache shutdown
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Parsing out mulitiple blocks of interesting data in files / ignoring other contents
by Athanasius (Archbishop) on Mar 02, 2016 at 13:40 UTC | |
by GeorgMN (Acolyte) on Mar 02, 2016 at 13:52 UTC | |
|
Re^3: Parsing out mulitiple blocks of interesting data in files / ignoring other contents
by Cristoforo (Curate) on Mar 02, 2016 at 13:42 UTC | |
by GeorgMN (Acolyte) on Mar 02, 2016 at 13:49 UTC |