需要帮助才能从输出下方找到字符串 NAME:“3640 chassis”和 SN:FF1045C5
术语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#
此致 Devraj
答案 0 :(得分:0)
所以,这是输入文件 test.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