log file parsing python

前端 未结 2 1779
滥情空心
滥情空心 2021-01-13 03:47

I have a log file with arbitrary number of lines. All I need is to extract is one line of data from the log file which starts with a string “Total”. I do not want any other

2条回答
  •  臣服心动
    2021-01-13 04:34

    for line in open('filename.txt', 'r'):
        if line.startswith('TestName') or line.startswith('Totals'):
            fields = line.rsplit(None, 5)
            print '\t'.join(fields[:2] + fields[3:4])
    

提交回复
热议问题