I need to extract the data elements in a data file containing curly brace neted data to produce a list of NAT pairs. For example, here is a dump from our Palo Alto FW:

------------------ Sample input { { { Prod1_Core_10.2.6.1 { to WAN; from WAN; source any; destination 8.39.63.3; service service-https; to-interface any; destination-translation { translated-address 10.2.6.1; } description "Static NAT to Core 10.2.6.1"; } Prod1_Core_10.2.6.2 { to WAN; from WAN; source any; destination 8.39.63.4; service service-https; to-interface any; destination-translation { translated-address 10.2.6.2; } description "Static NAT to Core 10.2.6.2"; } } } end sample input ---------------

Essentially, we want to extract these values:

>>>> Prod1_Core_10.2.6.2 { to WAN; from WAN; source any; >>>> destination 8.39.63.4; service service-https; to-interface any; destination-translation { >>>> translated-address 10.2.6.2; <<<<

From this data we need to produce a list of the nat pairs like:

queue = [ {:corename => "Prod1_Core_10.2.6.1", :pubip => "8.39.63.3", :privip + => "10.2.6.1"}, {:corename => "Prod1_Core_10.2.6.2", :pubip => "8.39.63.4", :privip +=> "10.2.6.2"}, ]

Is there a parser that will be able to map the data blocks in the nested data into single entities like a string?

any guidance is greatly appreciated :)

Daniel

2018-05-02 Athanasius changed pre to paragraph and code tags


In reply to Parsing { } nested data in a file by daniel99

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.