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です。私は正直にそれを正しく行うことを知りません...
私は次の人気順のソリューションを好むでしょう (私にとって): in sed(1)
(非常に高速である可能性があります)、in awk(1)
(私にとって前のものほど良くない)、in perl(1)
(理由はありません。単純な Perl のみを使用しstrict
、warnings
モジュールのみをソースとして使用する場合) ) またはANSI Cで追加のライブラリを使用せず、ベースのみ (ここでパーサーを書きたいと思う人はいないと思いますが、誰も知りません)。