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