【网络】【交换机】相关字符串处理

  1. textfsm
# py

from textfsm import TextFSM

output = '''
 N7K# show vlan

 VLAN Name  Status Ports
 ---- -------------------------------- --------- -------------------------------
 1 default active Eth1/1, Eth1/2, Eth1/3
  Eth1/5, Eth1/6, Eth1/7
 2 VLAN0002  active Po100, Eth1/49, Eth1/50
 3 VLAN0003 active Po100, Eth1/49, Eth1/50
 4 VLAN0004 active Po100, Eth1/49, Eth1/50
 5 VLAN0005 active Po100, Eth1/49, Eth1/50
 6 VLAN0006 active Po100, Eth1/49, Eth1/50
 7 VLAN0007 active Po100, Eth1/49, Eth1/50
 8 VLAN0008 active Po100, Eth1/49, Eth1/50
 '''

f = open('TextFSM_show_vlan.template')
template = TextFSM(f)

print(template.ParseText(output))
print (template.ParseTextToDicts(output))




# template
Value VLAN_ID (\d+)
Value NAME (\w+)
Value STATUS (\w+)

Start
 ^ ${VLAN_ID}\s+${NAME}\s+${STATUS}\s+ -> Record

posted @ 2021-09-10 14:11  该显示昵称已被使用了  阅读(52)  评论(0编辑  收藏  举报