Perhaps if I explain how the code works you can adapt it to your actual data? Here's the main part of code again:

my $lastIP; while (<DATA>) { print if /network name|interface name|VRID|state|primary address/i; print "$lastIP\n\n" if /Monitored circuits:/ and defined $lastIP; $lastIP = $1 if /((\d{1,3}\.){3}\d{1,3})/; }

$lastIP remembers the last IP address seen so it can be printed when "Monitored circuits" is noticed.

while (<DATA>) reads the data one line at a time. You would normally use a file handled that you had created with open inFile, '<', 'filename' in place of DATA.

print without parameters prints the contents of the default variable - in this case the data line that was last read from DATA. if /network name|i...address/i matches an interesting line (insensitive to case) and allows the print if there is a match.

print "$lastIP\n\n" prints the IP address preceeding the line containing "Monitored circuits".

This most important line is the one that matches "interesting lines". It does that by matching any of "network name", "interface name", "VRID", "state" or "primary address". Note the | between each string in the regular experssion pattern. They allow a match on any of the strings in the pattern.

You should be able to take that and extend the match to do what you require. If not, show us your attempt, what it prints, and what you would like it to print. Note that we only need pertinant data and only enough to demonstrate the problem. Otherwise the problem gets burried in clutter. Reduce your data to a bare minimum the shows the issue.


DWIM is Perl's answer to Gödel

In reply to Re^3: just another search program by GrandFather
in thread just another search program by sunny

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.