#!/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')

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐