/usr/share/doc/check-mk-doc/treasures/colorgrep is in check-mk-doc 1.2.8p16-1ubuntu0.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #!/usr/bin/python
# This is like egrep, but hilites the exact positions
# of *subexpressions*. This is e.g. usefull for testing
# inventory_processes...
import re, sys
def color(x):
if x == 0:
return "\033[0m"
else:
return "\033[1;3%dm" % x
def handle_line(r, line):
m = r.search(line)
if m:
start, end = m.span(0)
spans = []
if m.lastindex:
for i in range(1, m.lastindex+1):
spans.append(m.span(i))
out = ""
out += line[0:start]
pos = start
for b, e in spans:
out += color(4)
out += line[pos:b]
out += color(1)
out += line[b:e]
pos = e
out += color(4)
out += line[pos:end]
out += color(0)
out += line[end:]
print out
r = re.compile(sys.argv[1])
for line in sys.stdin:
handle_line(r, line[:-1])
|