Pavanai has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

show route summary Autonomous system number: 32934 Router ID: 100.100.100.100 inet.0: 498154 destinations, 3436699 routes (498150 active, 0 holddown +, 5 hidden) Restart Complete Direct: 15 routes, 14 active Local: 22 routes, 22 active BGP: 3426353 routes, 487808 active Static: 38 routes, 38 active IS-IS: 10268 routes, 10268 active RSVP: 3 routes, 0 active inet.3: 10103 destinations, 10107 routes (10103 active, 0 holddown, 0 +hidden) Restart Complete IS-IS: 10006 routes, 10002 active RSVP: 101 routes, 101 active iso.0: 2 destinations, 2 routes (2 active, 0 holddown, 0 hidden) Restart Complete Direct: 2 routes, 2 active mpls.0: 6 destinations, 6 routes (6 active, 0 holddown, 0 hidden) Restart Complete MPLS: 6 routes, 6 active inet6.0: 25299 destinations, 115803 routes (25299 active, 0 holddown, +0 hidden) Restart Complete Direct: 14 routes, 10 active Local: 23 routes, 23 active BGP: 115500 routes, 25000 active Static: 101 routes, 101 active IS-IS: 165 routes, 165 active

I need to capture only the active routes, 498150 , 10103 and 25299 from the above output. The test will be passed only if all the 3 matches are successful. Is there a way to do a pattern matching for this?

Replies are listed 'Best First'.
Re: Capturing route details
by arkturuz (Curate) on Nov 17, 2014 at 14:00 UTC
    Hello!

    First thing: your post is unreadable. Try putting <code></code> tags around the route summary text. The other thing: post your solution to this and let us review it. It's not fair if we're doing all the work :)

    You can match the desired text in many different ways as long as they're unique for the data lines you want matched. A simple regexp can match these active lines:

    while (defined(my $line = <STDIN>)) { if ($line =~ /^inet\((\d+) active/) { print $line; } }

    Output:

    inet.0: 498154 destinations, 3436699 routes (498150 active, 0 holddown +, 5 hidden) inet.3: 10103 destinations, 10107 routes (10103 active, 0 holddown, 0 +hidden) inet6.0: 25299 destinations, 115803 routes (25299 active, 0 holddown, +0 hidden)
Re: Capturing route details
by davido (Cardinal) on Nov 17, 2014 at 15:59 UTC

    I don't understand the objective. Why do 498150, 10103, and 25299 qualify, but not 2 and 6? It may be as simple as "because they're only a single digit", but I wouldn't want to make assumptions. What do you want to capture?

    If you still need a useful answer, please provide more information. Assume we don't know anything about what you're trying to accomplish (because we don't).


    Dave