关于将交换机多端口多行配置块合并为数组单个元素的技术咨询
将交换机多端口多行配置块合并为数组单个元素的技术咨询
嗨,针对你想把交换机多个以太网端口的多行配置块转换成数组单个元素的需求,我来给你整理一下!先把你提供的原始配置放出来,再给你输出转换后的结果:
原始交换机端口配置
Interface Ethernet1/0/12 switchport mode hybrid switchport hybrid allowed vlan 21-29 untag switchport hybrid native vlan 21 mac-authentication-bypass enable mac-authentication-bypass guest-vlan 21 Interface Ethernet1/0/13 switchport mode hybrid switchport hybrid allowed vlan 21-29 untag switchport hybrid native vlan 21 mac-authentication-bypass enable mac-authentication-bypass guest-vlan 21 Interface Ethernet1/0/14 switchport mode hybrid switchport hybrid allowed vlan 21-29 untag switchport hybrid native vlan 21 mac-authentication-bypass enable mac-authentication-bypass guest-vlan 21 Interface Ethernet1/0/15 switchport mode hybrid switchport hybrid allowed vlan 21-29 untag switchport hybrid native vlan 21 mac-authentication-bypass enable mac-authentication-bypass guest-vlan 21
转换为数组单个元素后的结果
这里我用通用的JSON数组格式呈现,每个端口的完整配置块作为数组的独立字符串元素,换行用\n转义以便代码处理:
[ "Interface Ethernet1/0/12\n switchport mode hybrid\n switchport hybrid allowed vlan 21-29 untag\n switchport hybrid native vlan 21\n mac-authentication-bypass enable\n mac-authentication-bypass guest-vlan 21", "Interface Ethernet1/0/13\n switchport mode hybrid\n switchport hybrid allowed vlan 21-29 untag\n switchport hybrid native vlan 21\n mac-authentication-bypass enable\n mac-authentication-bypass guest-vlan 21", "Interface Ethernet1/0/14\n switchport mode hybrid\n switchport hybrid allowed vlan 21-29 untag\n switchport hybrid native vlan 21\n mac-authentication-bypass enable\n mac-authentication-bypass guest-vlan 21", "Interface Ethernet1/0/15\n switchport mode hybrid\n switchport hybrid allowed vlan 21-29 untag\n switchport hybrid native vlan 21\n mac-authentication-bypass enable\n mac-authentication-bypass guest-vlan 21" ]
如果你需要其他编程语言的数组格式(比如Python列表、YAML数组),或者对换行处理有特殊要求,随时告诉我就行!
备注:内容来源于stack exchange,提问作者Catcher Rem
相关产品推荐
相关产品推荐

