log file parsing python

前端 未结 2 1791
滥情空心
滥情空心 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:37

    theFile = open('thefile.txt','r')
    FILE = theFile.readlines()
    theFile.close()
    printList = []
    for line in FILE:
        if ('TestName' in line) or ('Totals' in line):
             # here you may want to do some splitting/concatenation/formatting to your string
             printList.append(line)
    
    for item in printList:
        print item    # or write it to another file... or whatever
    

提交回复
热议问题