Skip to content

Instantly share code, notes, and snippets.

@peterhil
Created November 6, 2013 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhil/7332758 to your computer and use it in GitHub Desktop.
Save peterhil/7332758 to your computer and use it in GitHub Desktop.
Simple grep with Python
#!/usr/bin/env python
"""Usage: grep.py regexp file"""
import re, sys
if len(sys.argv) < 3:
print(__doc__)
exit(1)
regexp = re.compile(sys.argv[1]);
with open(sys.argv[2], 'rb') as file:
for line in file:
match = re.match(regexp, line)
if match:
sys.stdout.write(line)
@davidgarvey
Copy link

egrep;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment