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

In reply to Re^2: Parsing out mulitiple blocks of interesting data in files / ignoring other contents by GeorgMN
in thread Parsing out mulitiple blocks of interesting data in files / ignoring other contents by GeorgMN

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.