从cli字符串输出中识别键和值的算法

2021-12-08 05:44:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个命令show interface transciever,它的输出可能会有所不同。 我收集了不同场景下该命令的一些示例输出。你知道吗

Ethernet1/2
    transceiver is present
    type is 1000base-T
    name is CISCO-METHODE
    part number is SP7041-E-R
    revision is --
    serial number is MTC19350BBK
    nominal bitrate is 1300 MBit/sec
    Link length supported for copper is 100 m
    cisco id is 3
    cisco extended id number is 4

Ethernet1/3
    transceiver is present
    type is 1000base-T
    name is CISCO-METHODE
    part number is SP7041-E
    revision is E
    serial number is MTC150303LW
    nominal bitrate is 1300 MBit/sec
    Link length supported for copper is 100 m
    cisco id is 3
    cisco extended id number is 4

Ethernet1/4
    transceiver is present
    type is 1000base-T
    name is CISCO-METHODE
    part number is SP7041-E
    revision is E
    serial number is MTC1731072M
    nominal bitrate is 1300 MBit/sec
    Link length supported for copper is 100 m
    cisco id is 3
    cisco extended id number is 4

Ethernet1/5
    transceiver is not present

Ethernet1/6
    transceiver is not present

Ethernet1/7
    transceiver is present
    type is 10Gbase-SR
    name is CISCO-AVAGO
    part number is SFBR-709SMZ-CS1
    revision is G4.1
    serial number is AVD1718A4WN
    nominal bitrate is 10300 MBit/sec
    Link length supported for 50/125um OM2 fiber is 82 m
    Link length supported for 62.5/125um fiber is 26 m
    Link length supported for 50/125um OM3 fiber is 300 m
    cisco id is 3
    cisco extended id number is 4
    cisco part number is 10-2415-03
    cisco product id is SFP-10G-SR
    cisco vendor id is V03

^^一些样品。 我想比较这些不同的样本,并确定潜在的键和值。你知道吗

比如:

  • 收发器存在
  • 收发器不存在

transceiver is可以是键,present/not present可以是值。 类似地,我想解析这些输出示例以识别其他键和值。有没有一个标准的算法可以让我朝着正确的方向去实现这个目标。你知道吗