需要帮助才能从下面的输出中找到字符串名称:"3640机箱">和SN:FF1045C5
术语 len 0
R1#sh 库存
名称:"3640 机箱">,DESCR:"3640 机箱">
PID: , VID: 0xFF, SN: FF1045C5
名称:"单端口快速以太网TX">,DESCR:"单端口快速以太网TX">
PID: NM-1FE-TX= , VID: 1.0, SN: 7720321
名称:"单端口快速以太网TX">,DESCR:"单端口快速以太网TX">
PID: NM-1FE-TX= , VID: 1.0, SN: 7720321
名称:"单端口快速以太网TX">,DESCR:"单端口快速以太网TX">
PID: NM-1FE-TX= , VID: 1.0, SN: 7720321
名称:"单端口快速以太网TX">,DESCR:"单端口快速以太网TX">
PID: NM-1FE-TX= , VID: 1.0, SN: 7720321
R1#
问候德夫拉吉
所以,这是输入文件测试.txt:
term len 0
R1#sh inventory
NAME: "3640 chassis", DESCR: "3640 chassis"
PID: , VID: 0xFF, SN: FF1045C5
NAME: "One port Fastethernet TX", DESCR: "One port Fastethernet TX"
PID: NM-1FE-TX= , VID: 1.0, SN: 7720321
NAME: "One port Fastethernet TX", DESCR: "One port Fastethernet TX"
PID: NM-1FE-TX= , VID: 1.0, SN: 7720321
NAME: "One port Fastethernet TX", DESCR: "One port Fastethernet TX"
PID: NM-1FE-TX= , VID: 1.0, SN: 7720321
NAME: "One port Fastethernet TX", DESCR: "One port Fastethernet TX"
PID: NM-1FE-TX= , VID: 1.0, SN: 7720321
R1#
这可能会有所帮助:
with open("test.txt") as f:
for eachLine in f:
if 'NAME: "3640 chassis"' in eachLine or 'SN: FF1045C5' in eachLine:
print "match found in line: ", eachLine
输出将如下所示:
match found in line: NAME: "3640 chassis", DESCR: "3640 chassis"
match found in line: PID: , VID: 0xFF, SN: FF1045C5