Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
Created April 6, 2022 10:11
Show Gist options
  • Select an option

  • Save JohannesBuchner/3d4b7daed5a41565098c83e8b50740b4 to your computer and use it in GitHub Desktop.

Select an option

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.
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