I have the following text in many files, standard Cisco switch stuff and I need to script something that will parse many text files and print if the command "spanning-tree guard root" is enabled on each interface. i.e. I want to search where is enabled, and return the file\interface in a print.

! interface FastEthernet1/0/3 switchport access vlan 300 switchport mode access switchport port-security maximum 130 switchport port-security switchport port-security aging time 2 switchport port-security aging type inactivity no logging event link-status speed 100 duplex full srr-queue bandwidth share 1 60 30 10 srr-queue bandwidth shape 3 0 0 0 mls qos trust device cisco-phone storm-control broadcast level pps 1k storm-control multicast level pps 2k storm-control action shutdown storm-control action trap spanning-tree portfast spanning-tree bpduguard enable spanning-tree guard root !

In reply to search for a string and return previous relating string if found by Anonymous Monk

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.