Fast streaming pattern search in large log files without loading entire file into memory.
- Stream mode: Reads line-by-line, handles GB-size logs efficiently
- Pattern matching: Regex support for flexible search
- Count limiting: Stop after N matches found (default: 10)
- Line number display: Optional line numbers in output
- Support both stdin & file paths
Perfect for troubleshooting massive log files where grep loads everything into memory.
# Download and run directly
git clone https://github.com/Poolion/log-grep.git
cd log-grep
python3 log-grep.py "error" bigfile.logOr add to PATH:
cp log-grep.py /usr/local/bin/python log-grep.py "ERROR" app.log
# Prints first 10 matches with line numberspython log-grep.py "connection timeout" -c 5
# Only show 5 matchespython log-grep.py "^INFO.*user" logfile.log --count 0
# Shows all matching linespython log-grep.py "failed login" --no-line-numberspython log-grep.py "503.*error" access.log | head -20Standard grep loads entire file into memory. For GB-size logs (common in cloud deployments), this wastes RAM and can cause out-of-memory errors.
Log Grep uses Python's built-in streaming file iteration (file descriptor stays open, one line read at a time) to handle arbitrarily large files efficiently.
| Pattern | Description |
|---|---|
ERROR |
Matches lines containing "ERROR" |
^TIMEOUT |
Lines starting with TIMEOUT |
\d{4}-\d{2}-\d{2} |
Date patterns in logs |
[0-9]{3}\.[0-9]+ |
Version numbers |
If you find this useful, you can support development: https://www.buymeacoffee.com/poolion