{"id":13586107,"url":"https://github.com/rtulke/rp","last_synced_at":"2026-02-28T18:06:38.480Z","repository":{"id":16718581,"uuid":"19475565","full_name":"rtulke/rp","owner":"rtulke","description":"rp aka red pencil is a simple multicolor command-line tool to highlight the filtered output text.","archived":false,"fork":false,"pushed_at":"2024-05-15T17:28:42.000Z","size":193,"stargazers_count":10,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-16T05:56:30.382Z","etag":null,"topics":["color","command-line","command-line-tool","egrep","grep","highlight","mark","pencil","python","rp","rpen","select","text"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtulke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-05-06T00:19:48.000Z","updated_at":"2024-08-01T16:32:06.694Z","dependencies_parsed_at":"2024-04-06T01:26:58.068Z","dependency_job_id":"8fda0b8e-e7a8-4c85-9b70-ac28c4664011","html_url":"https://github.com/rtulke/rp","commit_stats":null,"previous_names":["rtulke/rpen"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtulke%2Frp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtulke%2Frp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtulke%2Frp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtulke%2Frp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtulke","download_url":"https://codeload.github.com/rtulke/rp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247670446,"owners_count":20976570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color","command-line","command-line-tool","egrep","grep","highlight","mark","pencil","python","rp","rpen","select","text"],"created_at":"2024-08-01T15:05:20.038Z","updated_at":"2026-02-28T18:06:38.472Z","avatar_url":"https://github.com/rtulke.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"rp\n==\n\nrp - red pencil is a simple multicolor command-line tool to highlight the filtered output text with multi-pattern highlighting, regex support, and advanced statistics. Each search pattern gets its own color, making it easy to visually distinguish multiple patterns in log files and text output.\n\nI always had problems with filtering out large continuous text, i.e. text that you want to filter out of log files with cat or something similar. So I needed a tool that makes it easy to see what I'm actually looking for.\n\n![Example](/images/rpen1.png)\n\n\n## Features\n\n- **Multi-color highlighting** - Each pattern gets a unique color\n- **Full regex support** - Use powerful regular expressions\n- **Statistics mode** - Get detailed match counts per pattern\n- **File and directory support** - Search single files or recursively\n- **Context lines** - Show lines before/after matches (like `grep -A/-B/-C`)\n- **Multiple output modes** - Count, only-matching, invert, and more\n- **Performance optimized** - Single-pass processing\n- **Robust** - Handles binary files, unicode, broken pipes\n\n## Requirements\n\n* Python 3.6\n* egrep or grep, grep should be GNU Version 3.x\n\n## Installation Linux, macOS\n\n```bash\n# clone repository\ngit clone https://github.com/rtulke/rp.git\n\n# for system wide installation\ncp rp/rp.py /usr/local/bin/rp\nchmod +x /usr/local/bin/rp\n\n# or optinal use symlink insted of copy to /usr/local/bin\n# ln -s $(pwd)/rp.py /usr/local/bin\n```\n\nMac OS X uses BSD grep or egrep, which are not 100% compatible with Linux grep/egrep. Most functions should work. If you encounter any problems, please create an issue.\n\n## Quick Start\n\n```bash\n# Basic usage with stdin\ncat error.log | rp ERROR WARN INFO\n\n# Search in files\nrp \"exception\" application.log\n\n# Multiple patterns with colors\nrp \"error|ERROR\" \"warn|WARN\" \"info|INFO\" system.log\n\n# Recursive directory search\nrp -r -i \"todo|fixme|hack\" ~/projects/\n\n# With line numbers and context\nrp -n -C 3 \"CRITICAL\" system.log\n```\n\n## Usage\n\n```\nrp [OPTIONS] PATTERN [PATTERN...] [FILE...]\n```\n\n### Basic Options\n\n| Option | Description |\n|--------|-------------|\n| `-i, --ignore-case` | Ignore case distinctions in patterns |\n| `-k, --display-all` | Display all lines, only highlight matches |\n| `-v, --invert-match` | Select non-matching lines |\n| `-w, --word-regexp` | Match only whole words |\n\n### Output Control\n\n| Option | Description |\n|--------|-------------|\n| `-n, --line-number` | Print line numbers with output |\n| `-c, --count` | Print only count of matching lines |\n| `-o, --only-matching` | Print only matched parts of lines |\n| `--stats` | Display detailed statistics about matches |\n\n### Context Control\n\n| Option | Description |\n|--------|-------------|\n| `-A NUM, --after-context NUM` | Print NUM lines after match |\n| `-B NUM, --before-context NUM` | Print NUM lines before match |\n| `-C NUM, --context NUM` | Print NUM lines before and after match |\n\n### File Handling\n\n| Option | Description |\n|--------|-------------|\n| `-r, --recursive` | Search directories recursively |\n| `-I, --no-binary` | Skip binary files automatically |\n| `-f FILE, --file FILE` | Read patterns from FILE (one per line) |\n\n## Examples\n\n### Basic Searching\n\n```bash\n# Single pattern\ncat app.log | rp \"ERROR\"\n\n# Multiple patterns with different colors\ncat app.log | rp \"ERROR\" \"WARN\" \"INFO\"\n\n# Case-insensitive search\ncat app.log | rp -i \"error\" \"warning\"\n\n# Show all lines, only highlight\ncat config.txt | rp -k \"TODO\" \"FIXME\"\n```\n\n### Regex Patterns\n\n```bash\n# IP addresses\ncat access.log | rp \"\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b\"\n\n# Email addresses\ncat dump.txt | rp \"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\"\n\n# Timestamps\ncat system.log | rp \"\\d{4}-\\d{2}-\\d{2}\" \"\\d{2}:\\d{2}:\\d{2}\"\n\n# Multiple error types\ncat error.log | rp \"err(or)?\" \"warn(ing)?\" \"exception\"\n```\n\n### File Operations\n\n```bash\n# Single file\nrp \"pattern\" file.log\n\n# Multiple files\nrp \"error\" *.log\n\n# Recursive directory search\nrp -r \"TODO\" ~/projects/\n\n# Recursive with case-insensitive\nrp -r -i \"fixme\" /var/log/\n\n# Skip binary files\nrp -r -I \"search term\" /usr/share/\n```\n\n### Context Lines\n\n```bash\n# 3 lines after each match\nrp -A 3 \"ERROR\" app.log\n\n# 2 lines before each match\nrp -B 2 \"Exception\" debug.log\n\n# 3 lines before and after\nrp -C 3 \"CRITICAL\" system.log\n\n# Context with line numbers\nrp -n -C 2 \"error\" application.log\n```\n\n### Output Modes\n\n```bash\n# Count matches only\nrp -c \"error\" *.log\n\n# Count per file\nrp -c \"warning\" file1.log file2.log file3.log\n\n# Show only matching parts\nrp -o \"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\" access.log\n\n# Invert match (exclude lines)\nrp -v \"DEBUG\" application.log\n\n# Line numbers\nrp -n \"error\" app.log\n```\n\n### Statistics Mode\n\n```bash\n# Basic statistics\nrp --stats \"ERROR\" \"WARN\" \"INFO\" application.log\n\n# Output:\n# [... colored matches ...]\n#\n# === Statistics ===\n# Total lines processed: 10000\n# Lines with matches: 847\n# Match rate: 8.47%\n#\n# Pattern matches:\n#   ERROR: 42\n#   WARN : 128\n#   INFO : 677\n\n# Statistics with count mode\nrp --stats -c \"error|exception\" *.log\n\n# Statistics without match output\nrp --stats -c \"pattern\" large.log\n```\n\n### Pattern Files\n\nCreate a pattern file (`patterns.txt`):\n\n```text\n# Security-related patterns\nauthentication.*failed\npermission.*denied\nunauthorized.*access\n\n# Error patterns\n\\b(error|exception|fatal)\\b\n\n# Network patterns\n\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\n```\n\nUse the pattern file:\n\n```bash\n# From file only\nrp -f patterns.txt access.log\n\n# Combine file and command-line patterns\nrp -f patterns.txt \"CRITICAL\" system.log\n\n# With statistics\nrp -f security-patterns.txt --stats -r /var/log/\n\n# Recursive with pattern file\nrp -f patterns.txt -r -I ~/logs/\n```\n\n### Advanced Combinations\n\n```bash\n# Full log analysis\nrp -f patterns.txt --stats -n -C 2 -i -r /var/log/\n\n# Security audit\nrp -f security-patterns.txt -r -I --stats /var/log/ 2\u003e/dev/null\n\n# Development workflow\nrp -r -i \"TODO|FIXME|HACK|XXX\" --stats ~/project/src/\n\n# Monitor logs in real-time\ntail -f app.log | rp \"ERROR\" \"EXCEPTION\" \"CRITICAL\"\n\n# Find specific issues with context\nrp -n -C 5 \"OutOfMemory|StackOverflow\" *.log\n```\n\n## Pattern File Format\n\nPattern files support:\n- One pattern per line\n- Comments starting with `#`\n- Empty lines (ignored)\n- Full regex syntax\n\nExample (`patterns.txt`):\n```text\n# HTTP status codes\n\\b[45]\\d{2}\\b\n\n# Common log levels\nERROR\nWARNING\nCRITICAL\n\n# IP addresses\n\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b\n```\n\n## Exit Codes\n\n| Code | Meaning |\n|------|---------|\n| 0 | Matches found |\n| 1 | No matches found |\n| 2 | Error occurred |\n| 130 | Interrupted (Ctrl+C) |\n| 141 | Broken pipe |\n\n## Performance\n\n**Optimizations:**\n- Single-pass processing (no repeated pipe overhead like v3)\n- Pre-compiled regex patterns\n- Efficient context buffer with deque\n- Lazy file iteration\n- Binary file detection (first 8KB)\n\n**Benchmarks** (1M lines, 4 patterns):\n```\ngrep (4 calls): ~3.5s\nrp v3:          ~4.2s (grep-based, multiple passes)\nrp v5:          ~1.8s (Python, single pass)\n```\n\n## Comparison with grep\n\n| Feature | grep | rp |\n|---------|------|-----|\n| Multi-color highlighting | ❌ | ✅ |\n| Regex support | ✅ | ✅ |\n| Context lines | ✅ | ✅ |\n| Statistics | ❌ | ✅ |\n| Pattern files | ✅ | ✅ |\n| Performance | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |\n| Single pattern | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |\n| Multiple patterns | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |\n\n## Use Cases\n\n### Security Analysis\n```bash\nrp -f security-patterns.txt --stats -r /var/log/\n```\n\n### Development\n```bash\nrp -r \"TODO|FIXME|HACK\" --stats src/\n```\n\n### Log Monitoring\n```bash\ntail -f app.log | rp \"ERROR\" \"WARN\" \"EXCEPTION\"\n```\n\n### Incident Response\n```bash\nrp -n -C 5 \"OutOfMemory|Segfault|Panic\" *.log\n```\n\n### Code Review\n```bash\nrp -r -i \"password|secret|key|token\" --stats .\n```\n\n## Tips \u0026 Tricks\n\n### Color Output in Less\n```bash\nrp \"pattern\" file.log | less -R\n```\n\n### Save Colored Output\n```bash\nrp \"pattern\" file.log \u003e output.txt  # No colors\nscript -c 'rp \"pattern\" file.log' output.txt  # With colors\n```\n\n### Combine with Other Tools\n```bash\n# With find\nfind . -name \"*.log\" -exec rp \"ERROR\" {} +\n\n# With xargs\ncat file-list.txt | xargs rp \"pattern\"\n\n# With awk\ncat data.txt | awk '{print $3}' | rp \"pattern\"\n```\n\n### Word Boundaries\n```bash\n# Match \"test\" but not \"testing\"\nrp -w \"test\" file.txt\n\n# Multiple whole words\nrp -w \"error\" \"warning\" \"info\" log.txt\n```\n\n## Troubleshooting\n\n### Binary File Warnings\n```bash\n# Skip binary files automatically\nrp -I \"pattern\" /path/\n\n# Or redirect stderr\nrp \"pattern\" /path/ 2\u003e/dev/null\n```\n\n### Performance Issues\n```bash\n# Use simpler patterns when possible\nrp \"ERROR\" instead of \"E[RR]*O[RR]*\"\n\n# Limit recursion depth (use find)\nfind /path -maxdepth 2 -name \"*.log\" -exec rp \"pattern\" {} +\n```\n\n### Unicode Issues\nUnicode is handled with `errors='replace'` - invalid sequences are replaced with �\n\n## Contributing\n\nContributions welcome! Please ensure:\n- Code follows PEP 8\n- All features have examples\n- Error handling is robust\n- Performance is tested\n- One single file ;)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtulke%2Frp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtulke%2Frp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtulke%2Frp/lists"}