2011-03-25 6 views
1

Junosのような構成データを「CSVのような」データの種類にエクスポートするスクリプトが必要ですタブで区切られている)と戻る。次のように試料(及びは、私の知る限り十分)の入力があってもよい。Junosのような(ツリー)構成データをCSVのような(テーブル)データに "エクスポート"するスクリプト

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; 
     } 
    } 
} 

(バー「|」タブが予想される場所を示す)を以下のように予想される出力は次のようになります

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; 

時を最初の一見、問題はかなり容易に思われるが、二重引用符のためにではない。 問題はIMHOいくつかの余分な二重引用符を扱う "tree-to-table"と "table-to-tree"問題に還元可能です。私は正直にそれを正しく行うことを知らない...

sed(1)(非常に高速かもしれない)で、次の順番で解決策を好むだろう:awk(1)私はperl(1)で(strictwarningsモジュールをソースとした単純なPerlのみを使用しているのであれば)、またはANSI Cで、余分なライブラリがなくても、基本的に(私はここで私にパーサーを書いてほしいとは思わないすべて、しかし誰も知らない)。

答えて

0

これは、JUNOSが組み込まれているのサポートXMLから変換する非常に簡単です:

show configuration | display set 
を試し、

show configuration | display xml 

いっそ

関連する問題