Python read log files and get lines containing specific words

后端 未结 2 1888
一整个雨季
一整个雨季 2020-12-30 13:50

I have log files ( named in the format YYMMDD ) and I\'d like to create a script that get only important information from the files ( like the lines that contains \"O:NVS:V

2条回答
  •  借酒劲吻你
    2020-12-30 14:36

    You'll need to know how to loop over files in a directory, regular expressions to make sure your log file format matches to file you are looping over, how to open a file, how to loop over the lines in the open file, and how to check if one of those lines contains what you are looking for.

    And here some code to get you started.

    with open("log.log" 'r') as f:
        for line in f:
            if "O:NVS:VOICE" in line:
                print line
    

提交回复
热议问题