A Python implementation of the Unix grep command line tool, following the Coding Challenges specification.
- Basic pattern matching with regular expressions
- Support for special patterns:
\d- matches any digit\w- matches any word character^- matches start of line$- matches end of line
- Command line options:
-i, --ignore-case: Case insensitive search-n, --line-number: Show line numbers-c, --count: Show only count of matching lines-r, --recursive: Recursively search directories-v, --invert-match: Show non-matching lines
No installation required. Just make sure you have Python 3.x installed on your system.
python grep.py [OPTIONS] PATTERN [FILE...]- Search for a simple pattern:
python grep.py "pattern" file.txt- Case-insensitive search:
python grep.py -i "Pattern" file.txt- Show line numbers:
python grep.py -n "pattern" file.txt- Count matching lines:
python grep.py -c "pattern" file.txt- Recursive search:
python grep.py -r "pattern" directory/- Invert match (show non-matching lines):
python grep.py -v "pattern" file.txt- Using special patterns:
python grep.py "\d" file.txt # Match lines containing digits
python grep.py "\w" file.txt # Match lines containing word characters
python grep.py "^Start" file.txt # Match lines starting with "Start"
python grep.py "End$" file.txt # Match lines ending with "End"0: Match found1: No match found2: File not found or other error
- Written in Python 3
- Uses built-in
remodule for regular expressions - Handles binary files gracefully
- Supports UTF-8 encoded text files
- Windows PowerShell compatible
- Only supports UTF-8 encoded text files
- Regular expression syntax is limited to basic patterns
- No support for multiple patterns
Feel free to submit issues and enhancement requests!