Last active
July 20, 2025 03:41
-
-
Save hidsh/a3ee73315be6d654c0cc74f553d0c1a9 to your computer and use it in GitHub Desktop.
A trivial python script to follow the `tail`ing logs such as `dmesg -w`
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 | |
# | |
# Example usage: | |
# dmesg -w | myfilter.py -x foo bar baz | |
# | |
import sys | |
import re | |
import argparse | |
def parse_args(): | |
parser = argparse.ArgumentParser( | |
description="Filter out lines matching any of the given patterns." | |
) | |
parser.add_argument( | |
"-x", "--excludes", nargs="+", required=True, | |
help="Regex patterns to exclude (any match will skip the line)" | |
) | |
return parser.parse_args() | |
def main(): | |
args = parse_args() | |
patterns = [re.compile(p) for p in args.excludes] | |
for line in sys.stdin: | |
if any(p.search(line) for p in patterns): | |
continue | |
print(line, end='') | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment