Skip to content

apih99/grepPy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Grep Implementation

A Python implementation of the Unix grep command line tool, following the Coding Challenges specification.

Features

  • 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

Installation

No installation required. Just make sure you have Python 3.x installed on your system.

Usage

python grep.py [OPTIONS] PATTERN [FILE...]

Examples

  1. Search for a simple pattern:
python grep.py "pattern" file.txt
  1. Case-insensitive search:
python grep.py -i "Pattern" file.txt
  1. Show line numbers:
python grep.py -n "pattern" file.txt
  1. Count matching lines:
python grep.py -c "pattern" file.txt
  1. Recursive search:
python grep.py -r "pattern" directory/
  1. Invert match (show non-matching lines):
python grep.py -v "pattern" file.txt
  1. 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"

Exit Codes

  • 0: Match found
  • 1: No match found
  • 2: File not found or other error

Implementation Details

  • Written in Python 3
  • Uses built-in re module for regular expressions
  • Handles binary files gracefully
  • Supports UTF-8 encoded text files
  • Windows PowerShell compatible

Limitations

  • Only supports UTF-8 encoded text files
  • Regular expression syntax is limited to basic patterns
  • No support for multiple patterns

Contributing

Feel free to submit issues and enhancement requests!

About

A Python implementation of the Unix grep command line tool, following the Coding Challenges specification.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages