Python文本读取 按关键字查找文件内容,并保存为文件


Python文本读取 按关键字查找文件内容,并保存为文件

from os import replace
import re

file = "d:/gdshnd_scm_0.txt"

with open(file) as f:
    content = f.readlines()

if content:
    for line in content:
        if ("前台" in line) and ("20210324" in line) and ("0247402" in line) and ("10101118" in line):

            # line = re.sub('\t', ',', line)
            # print(line.replace(' ', ''), end='')
            with open('123.txt', 'a') as f:
                f.write(line)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM