Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Store multiple lines

by tybalt89 (Curate)
on Feb 09, 2018 at 14:59 UTC ( #1208837=note: print w/replies, xml ) Need Help??


in reply to Store multiple lines

#!/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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208837]
help
Chatterbox?
and not a whimper to be heard...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-02-20 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (268 votes). Check out past polls.

    Notices?