gpt4 book ai didi

python - 如何从文件中打印与大文本文件中的输入字符串匹配的特定行?

转载 作者:太空宇宙 更新时间:2023-11-04 00:51:59 25 4
gpt4 key购买 nike

这是我的代码,我的目标是从大文本文件打印特定的整行,当我尝试在对象中打印时,字符串等于“SAMPLE TYPE” 如何从整个文件打印指定的行

import re
target = open("debug.txt", "r")
for line in target:
search=re.search("[SAMPLE TYPE]",line)
v1=search
print v1

给出输出:

None
None
None
None
None
<_sre.SRE_Match object at 0x7f870b7d5578>in this place instead of this i need to print the specifed line and i dont want the lines which doesnt contain specifed string.

我的输入文件数据:

HLS| 04/14/16 17:56:58:933 |hls_tsr_module.cpp|ReceiveData              |418 |DEBUG: Data copied to TSD from TSR is 0
HLS| 04/14/16 17:56:58:933 |mpm_h264.cpp |FrameType |1341|DEBUG: AU_DELIM NALU Unit Type
HLS| 04/14/16 17:56:58:933 |mpm_h264.cpp |FrameType |1341|DEBUG: SEI NALU Unit Type
HLS| 04/14/16 17:56:58:933 |mpm_h264.cpp |FrameType |1341|DEBUG: NON_IDR_PICTURE NALU Unit Type
HLS| 04/14/16 17:56:58:933 |mpm_h264.cpp |FrameType |1377|DEBUG: B Frame Received
HLS| 04/14/16 17:56:58:933 |hls_tsd_module.cpp|ProcessVideoBuffer |4151|DEBUG: SAMPLE TYPE: B - FRAME PTS: 8573002542 DTS: 8573002542
HLS| 04/14/16 17:56:58:933 |hls_tsd_module.cpp|ProcessVideoBuffer |4193|DEBUG: Video send pts 8573002542
HLS| 04/14/16 17:56:58:933 |hls_tsm_module.cpp|AlternateFrameInterLeave |11770|DEBUG: Audio Record Status is 1
HLS| 04/14/16 17:56:58:934 |hls_tsd_module.cpp|ProcessVideoBuffer |4261|DEBUG: Frame video pts 8573004043
HLS| 04/14/16 17:56:58:934 |hls_tsm_module.cpp|AlternateFrameInterLeave |11770|DEBUG: Audio Record Status is 1
HLS| 04/14/16 17:56:58:934 |hls_tsd_module.cpp|SegmentStream |1597|DEBUG: Not an AV/Subtitle Packet 256
HLS| 04/14/16 17:56:58:934 |mpm_h264.cpp |FrameType |1341|DEBUG: AU_DELIM NALU Unit Type
HLS| 04/14/16 17:56:58:934 |mpm_h264.cpp |FrameType |1341|DEBUG: SEI NALU Unit Type
HLS| 04/14/16 17:56:58:934 |mpm_h264.cpp |FrameType |1341|DEBUG: NON_IDR_PICTURE NALU Unit Type
HLS| 04/14/16 17:56:58:934 |mpm_h264.cpp |FrameType |1377|DEBUG: B Frame Received
HLS| 04/14/16 17:56:58:934 |hls_tsd_module.cpp|ProcessVideoBuffer |4151|DEBUG: SAMPLE TYPE: B - FRAME PTS: 8573004043 DTS: 8573004043

最佳答案

import os
os.system('grep -rnw "[FOLDER_NAME]" -e "SEARCH_STRING" > OP.txt')

关于python - 如何从文件中打印与大文本文件中的输入字符串匹配的特定行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36735770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com