#!/usr/bin/perl
# http://perlmonks.org/?node_id=1208816
use strict;
use warnings;
local $_ = do { local $/; <DATA> };
my %results;
# match two lines at a time
$results{$1}{$5}{$2}{$3} = $4 while /^(\S+):\s+ static-route\s(\S+)\s
next-hop\s(\S+) (?:\spreference\s\d+)? (?:\sbfd-enable)?\s tag\s(\d
++)
\n \1-\s* service-name\s"(\S+)"/gmx;
for my $box (sort keys %results)
{
print "\n$box\n";
for my $service (sort keys %{$results{$box}})
{
for my $static (sort keys %{$results{$box}{$service}})
{
for my $hop (sort keys %{$results{$box}{$service}{$static}})
{
print "$static\t next-hop $hop\t",
"tag $results{$box}{$service}{$static}{$hop}, service $servi
+ce\n";
}
}
}
}
__DATA__
dnsname1: static-route 1.1.1.1/30 next-hop 2.2.2.2 preferen
+ce 200 bfd-enable tag 685
dnsname1- service-name "XYZ12345-s12345"
dnsname2: static-route 3.3.3.3/30 next-hop 4.4.4.4 bfd-enab
+le tag 635
dnsname2- service-name "XYZ67891-s67890"
Outputs:
dnsname1
1.1.1.1/30 next-hop 2.2.2.2 tag 685, service XYZ12345-s123
+45
dnsname2
3.3.3.3/30 next-hop 4.4.4.4 tag 635, service XYZ67891-s678
+90
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|