You can use the os
and re
modules to achieve this task. Here's an example:
main.py572 chars18 lines
In this example, we're looking for all files with the .log
extension in the specified path
. Then, we're opening each file and reading its contents. For each file, we're looping through each line of the file and searching for the string "panic" using a regular expression. If we find a line with "panic", we print the filename and the line where the match was found.
gistlibby LogSnag