python 查找指定的字符串并且将其抽出
·

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import re
if os.path.exists('./parse_log.txt'):
os.remove('./parse_log.txt')
else:
print("no such file")
with open("./2021-01-15-21-24-09.log", 'r') as f:
for line in f:
expect_string = re.findall(".*timestamp = (.*)reg status.*", line)
expect_string = expect_string + re.findall(".*reg status(.*)reg_end.*", line)
print(expect_string)
if not len(expect_string):#列表非空
continue
with open('./parse_log.txt', 'a+', encoding='utf-8') as fp:
fp.write(','.join(expect_string)+'\n')
更多推荐




所有评论(0)