Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created September 23, 2014 13:42
Show Gist options
  • Save meeuw/805cec7c161a21202da2 to your computer and use it in GitHub Desktop.
Save meeuw/805cec7c161a21202da2 to your computer and use it in GitHub Desktop.
grep but only output what matches
#!/usr/bin/python
import fileinput
import sys
import re
pattern = sys.argv.pop(1)
for line in fileinput.input():
m = re.search(pattern, line)
if m:
for g in m.groups(): print g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment