<D <M <Y
M> D>

2008-04-10T22:04:23 Rewrite of greenbar:

Blogger wouldn't format this right, so I'm putting my response here.

Original post

Here's a version using the file iterator capabilities on stdin, enumerate for the line number, all the logic combined into one if-statement, and a different strategy for printing the highlights.

#!/usr/bin/python -u

import sys

try:
pat = sys.argv[1]
except IndexError:
pat = None

for lineno, line in enumerate(sys.stdin):
if (pat and pat in line) or (not pat and lineno % 2 == 0):
print "\x1b[7m%s\x1b[0m" % line.rstrip()
else:
print line,


[Main]

Unless otherwise noted, all content licensed by Drew Perttula
under a Creative Commons License.