我不知道perl是否可以解析大括號配置的junos並轉換爲csv。perl解析配置括號樣式
interfaces {
apply-groups policer-arp;
ge-1/0/0 {
description "*** Description ***";
unit 0 {
family inet {
address 10.100.200.1/24 {
arp 10.100.200.2 mac 00:16:d4:e7:9b:de;
}
}
}
}
ge-1/0/2 {
description " Description ";
vlan-tagging;
unit 101 {
description "NODEB_CLUSTER#101";
vlan-id 101;
family inet {
address 10.187.132.3/27 {
vrrp-group 1 {
virtual-address 10.187.132.1;
priority 190;
accept-data;
}
}
}
}
unit 102 {
description "Description";
vlan-id 102;
family inet {
address 10.187.132.35/27 {
vrrp-group 2 {
virtual-address 10.187.132.33;
priority 200;
accept-data;
}
}
}
}
unit 103 {
description "NODEB_CLUSTER#103";
vlan-id 103;
family inet {
address 10.187.132.67/27 {
vrrp-group 3 {
virtual-address 10.187.132.65;
priority 190;
accept-data;
}
}
}
}
unit 104 {
description "NODEB_CLUSTER#104";
vlan-id 104;
family inet {
address 10.187.132.99/27 {
vrrp-group 4 {
virtual-address 10.187.132.97;
priority 200;
accept-data;
}
}
}
}
輸出:
Interface, IP Address, VLAN, Virtual-Address, Vrrp-group, Vrrp Priority
ge-1/0/0,10.100.200.1/24, , , , ,
ge-1/0/2, , , , , ,
ge-1/0/2.101,10.187.132.3/27,101,10.187.132.1,1,190
ge-1/0/2,102,10.187.132.35/27,102,10.187.132.33,2,200
ge-1/0/2,103,10.187.132.67/27,103,10.187.132.65,3,190
ge-1/0/2,104,10.187.132.99/27,104,10.187.132.97,4,200
所以在短暫的,我們香橙配置轉換爲CSV,用於接口配置我們計數接口GE-1/0/2,比GE-1/0/2.101如它是vlan 101的接口,vlan 102的ge-1/0/2.102,等等。 Perl是否可以解析它,或者有沒有更快的方法來轉換它?
的Perl(或任何其他的編程語言)可以做到這一點。你有什麼嘗試? – choroba
我試着先讀輸入,然後grep if($ _ =〜//)。但是,當配置中存在重複值時,很難獲得該值。我想知道是否有更快的方法? – rabka