-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfindwords
More file actions
executable file
·32 lines (27 loc) · 846 Bytes
/
findwords
File metadata and controls
executable file
·32 lines (27 loc) · 846 Bytes
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
#!/usr/bin/env python
"""Usage: findwords word1 word2 ... wordN < sometext
Like grep, but prints out lines that contain all words.
See also quickcolorize which is similar but doesn't do filtering."""
# Dependencies:
# needs my waterworks library:
# https://github.com/dmcc/waterworks
# and
# ansicolors (https://pypi.org/project/ansicolors)
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
import sys
import colors
from QuickColorize import colorize
words = sys.argv[1:]
for line in sys.stdin:
skip = False
for word in words:
if word not in line:
skip = True
break
if not skip:
for word in words:
color_word = colorize(word)
line = line.replace(word, colors.color(color_word, style='bold'))
sys.stdout.write(line)