Note that there are some explanatory texts on larger screens.

plurals
  1. POScripts to "export" Junos-like (tree) configuration data to CSV-like (table) data and back
    primarykey
    data
    text
    <p>I would like to have some scripts to export Junos-like configuration data to sort of "CSV-like" data (separated by tabs) and back. The sample (and <strong>AFAIK</strong> sufficient) input may be as follows:</p> <pre><code>firewall { filter protect { term "protocol bgp" { from { prefix-list { bgp-peers; } protocol tcp; ## Any ideas how to preserve comments in output? port bgp; } then accept; } term protocol_ntp { from { prefix-list { "protocol ntp"; } protocol udp; port ntp; } then accept; } } } </code></pre> <p>The expected output would be as follows (bars "|" denote places where tabs are expected):</p> <pre><code>firewall|filter protect|term "protocol bgp"|from|prefix-list|bgp-peers; firewall|filter protect|term "protocol bgp"|from|protocol tcp; firewall|filter protect|term "protocol bgp"|from|port bgp; firewall|filter protect|term "protocol bgp"|then accept; firewall|filter protect|term protocol_ntp|from|prefix-list|"protocol ntp"; firewall|filter protect|term protocol_ntp|from|protocol udp; firewall|filter protect|term protocol_ntp|from|port ntp; firewall|filter protect|term protocol_ntp|then accept; </code></pre> <p>At first glance, the problem seems quite easy but at second it's not because of the double-quotes. The problem is <strong>IMHO</strong> reducable to "tree-to-table" and "table-to-tree" problem with some extra double-quotes handling. I honestly do not know to do that correctly...</p> <p>I would prefer solutions in next order by popularity (for me): in <code>sed(1)</code> (could be very fast), in <code>awk(1)</code> (not as nice as the former one to me), in <code>perl(1)</code> (why not, if using only plain Perl with just <code>strict</code> and <code>warnings</code> modules sourced) or in <strong>ANSI C</strong> without extra libraries, just the base (I do not expect anybody would like to write parsers for me here at all, but one never knows). </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload