Created
November 6, 2013 08:32
-
-
Save peterhil/7332758 to your computer and use it in GitHub Desktop.
Simple grep with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
egrep;)