Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import sys
- import os
- logz = [fn for fn in os.listdir(r'my text file directory') if fn.endswith('.txt')]
- err_occur = [] # The list where we will store results.
- pattern = re.compile(" error ", re.IGNORECASE)
- try: # Try to:
- with open ('logz', 'rt') as in_file: # open file for reading text.
- for linenum, line in enumerate(in_file):
- if pattern.search(line) != None:
- err_occur.append((linenum, line.rstrip('/n')))
- print("Line ", linenum, ": ", line, sep='')
- import pathlib
- def main():
- for path in pathlib.Path('.').iterdir():
- if path.suffix.lower() == '.txt':
- with path.open() as file:
- for line, text in enumerate(file):
- if 'error' in text.lower():
- print(f'Line {line}: {text}')
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement