#!/usr/bin/python import fileinput, sys, re pattern = sys.argv.pop(0) regexp = re.compile(pattern) for line in fileinput.input(): if regexp.search(line): print line