Dqstr - - -wnh 1 !!hot!!
word_match = 'w' in opts line_numbers = 'n' in opts no_filename = 'h' in opts # not needed for stdin
lines = sys.stdin.read().splitlines() for idx, line in enumerate(lines, 1): match = re.search(rf'\bpattern\b' if word_match else pattern, line) if match: if line_numbers: print(f"idx:line" if not no_filename else f"idx:line") else: print(line) if == " main ": dqstr() dqstr - -wnh 1
1 hello 1 world Running echo -e "1\nhello 1\nworld" | dqstr - -wnh 1 would output: word_match = 'w' in opts line_numbers = 'n'
if '-' in args: stdin_mode = True args.remove('-') line in enumerate(lines
#!/usr/bin/env python3 import sys import re def dqstr(): args = sys.argv[1:] stdin_mode = False opts = [] pattern = None
