/bin/re-commands
Python | 26 lines | 20 code | 4 blank | 2 comment | 5 complexity | 222968d0961f35baea4acd9b2a3c5e75 MD5 | raw file
Possible License(s): WTFPL
- #!/usr/bin/env python
- import os
- import re
- import sys
- checks = []
- args = iter(sys.argv[1:])
- for regex, command in zip(args, args):
- checks.append((
- re.compile(regex),
- command,
- ))
- while True:
- #for line in sys.stdin:
- line = sys.stdin.readline()
- if not line:
- break
- line = line[:-1]
- for regex, command in checks:
- if regex.match(line):
- os.system(
- regex.sub(command, line)
- )