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

  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

原文地址:https://www.cnblogs.com/amize/p/15251094.html