Skip to content

Instantly share code, notes, and snippets.

@migonzalvar
Created June 25, 2014 08:37
Show Gist options
  • Save migonzalvar/884a94660c83a46a1bb4 to your computer and use it in GitHub Desktop.
Save migonzalvar/884a94660c83a46a1bb4 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
""" grep.py - Search a string in a file. """
import sys
# Parse arguments
pattern, file_name = sys.argv[1:3]
with open(file_name, 'rt') as f:
for n, line in enumerate(f, 1):
if pattern in line:
print('Line %03d:' % n, line, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment