Created
August 5, 2022 19:14
-
-
Save apocalyptech/b33dba8a90ee99d10fa60fded5356da4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # vim: set expandtab tabstop=4 shiftwidth=4: | |
| import os | |
| import re | |
| import sys | |
| date_re = re.compile('^\d+:\d+:\d+\.\d+: (?P<rest>.*)$') | |
| pid_re = re.compile('^(?P<app>[-a-zA-Z0-9]+)\[(?P<pid>\d+)\]: (?P<rest>.*)$') | |
| os.makedirs('stripped', exist_ok=True) | |
| for filename in os.listdir('.'): | |
| if filename.startswith('slr-') and filename.endswith('.log'): | |
| new_filename = os.path.join('stripped', filename) | |
| with open(filename) as df: | |
| with open(new_filename, 'w') as odf: | |
| for line in df: | |
| line = line.strip() | |
| if match := date_re.match(line): | |
| line = match.group('rest') | |
| line = pid_re.sub('\g<app>[]: \g<rest>', line) | |
| print(line, file=odf) | |
| print(f'Stripped to: {new_filename}') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment