【发布时间】:2018-12-17 10:14:27
【问题描述】:
我是脚本新手,所以任何帮助都会大有帮助,
它更多与Cisco路由器配置文件有关,第一种格式是当你运行命令“show running-config”时,第二部分是当你使用命令“show running-config正式”时
所以,我想将我的 config txt 文件转换为以后的格式。
我的 linux 操作系统中有一个文件,其中包含以下数据,
control-plane
management-plane
inband
interface all
allow xy
address x.x.x.x
address y.y.y.y
!
allow b
address b.b.b.b
!
!
!
我想要的是删除它的格式,所以基本上像这样将子部分附加到父级,或者使用 linux 命令或使用 python 编写脚本。你认为最好的方法是什么?
control-plane management-plane inband interface all allow xy
control-plane management-plane inband interface all allow xy address x.x.x.x
control-plane management-plane inband interface all allow xy address y.y.y.y
control-plane management-plane inband interface all allow b
control-plane management-plane inband interface all allow b address b.b.b.b
使用相同的概念,我想在同一个文件中进一步重新格式化,
service sesh instance1
service-location preferred-active 0/3/CPU0
service-type nps nps-1
forced-placement npu 0
tunnel type gre
name gre10
tunnel-destination ipv4 address 209.165.200.225
ipv4 address 192.0.2.6/24
remote ipv4 address 192.0.2.5/24
tunnel-source ipv4 address 209.165.200.226
!
package nps-mips64-r2.rpm
interface ServiceApp1
remote ipv4 address 209.165.200.227/24
!
!
!
template pre-pos
interface preconfigure POS0/1/0/0
ipv4 address 10.3.32.154 255.0.0.0
!
我还附上了an image,只是为了给一个更清晰的图片。
谢谢
萨尔
【问题讨论】:
-
我不知道你是想在“允许”和“地址”行上输出,还是在树的最低两层,或者什么。我采用的方法是将文件转换为 Python 结构(在本例中为 list-of-lists-of-lists ...),将输入表示为树。然后,您可以将该树转换为您喜欢的任何序列化输出格式。
-
@MikeHousky- 嗨 Mike,所以我不确定你是否熟悉路由器,但第一个是当你运行命令“show running-config”时,第二部分是当你使用命令“显示运行配置正式”我想将我的配置文件转换为以后的格式。
-
不...无法识别该格式。如果这是一次性的,看起来你有一个答案。我的方法会比你真正需要的要重得多。
-
-
为什么需要或需要部分命令
control-plane management-plane inband interface all allow xy和… b?