#!/usr/bin/env python import sys, ansi from os import popen2, putenv terms = sys.argv[1:-1] filename = sys.argv[-1] # TODO: add more. do a dir(ansi) to find the rest colors = ansi.RED, ansi.GREEN, ansi.BLUE, ansi.YELLOW input = file(filename).read() putenv('GREP_OPTIONS', '--color=always') for t, c in zip(terms, colors): putenv('GREP_COLOR', c + ansi.BOLD[:-1]) pipein, pipeout = popen2('/usr/bin/grep "%s"' % t) pipein.write(input) pipein.close() input = pipeout.read() print input