需要帮助在python中切分单词吗

2024-10-03 13:26:00 发布

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

需要帮助从下面找到字符串名称:“3640 chassis”SN:FF1045C5

术语长度0

R1#sh库存

名称:“3640机箱”,描述:“3640机箱”

PID:,VID:0xFF,SN:FF1045C5

名称:“一端口Fastethernet TX”,描述:“一端口Fastethernet TX”

PID:NM-1FE-TX=,视频:1.0,序列号:7720321

名称:“一端口Fastethernet TX”,描述:“一端口Fastethernet TX”

PID:NM-1FE-TX=,视频:1.0,序列号:7720321

名称:“一端口Fastethernet TX”,描述:“一端口Fastethernet TX”

PID:NM-1FE-TX=,视频:1.0,序列号:7720321

名称:“一端口Fastethernet TX”,描述:“一端口Fastethernet TX”

PID:NM-1FE-TX=,视频:1.0,序列号:7720321

R1#

敬礼 德夫拉吉


Tags: 端口字符串名称视频pid机箱术语序列号
1条回答
网友
1楼 · 发布于 2024-10-03 13:26:00

这是输入文件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

相关问题 更多 >