Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/python
import re
import sys
import fileinput
if len(sys.argv) < 4:
sys.stderr.write("usage: %s <trigger regex> <begin regex> <end regex>\n" % sys.argv[0])
sys.exit(1)
regex = sys.argv.pop(1)
begin = sys.argv.pop(1)
end = sys.argv.pop(1)
buf = list()
searching = True
for line in fileinput.input():
if searching:
if re.search(begin, line):
buf = list()
if re.search(regex, line):
searching = False
buf.append(line)
if not searching:
if re.search(end, line):
searching = True
for item in buf:
sys.stdout.write(item)
sys.stdout.write("\n---------------------\n")
buf = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment