Created
April 6, 2022 10:11
-
-
Save JohannesBuchner/3d4b7daed5a41565098c83e8b50740b4 to your computer and use it in GitHub Desktop.
Strips duplicated and repeated lines from stdin (such as a log output). Can also handles multiline repeats, up to a configurable memory limit.
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
| import os | |
| import sys | |
| max_memory = int(os.environ.get('MAX_MEMORY', '10')) | |
| recent_lines = [] | |
| for line in sys.stdin: | |
| if line not in recent_lines: | |
| sys.stdout.write(line) | |
| recent_lines.append(line) | |
| if len(recent_lines) > max_memory: | |
| recent_lines.pop(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment