3 ms·
You can easily wrap python with a small script that makes it more useful as command line filtering tool. Most of the bloat actually just comes from importing pa
by Too 8y ago
You can easily wrap python with a small script that makes it more useful as command line filtering tool. Most of the bloat actually just comes from importing packages.
#!/usr/bin/python3
import re, sys, json, other, useful, packages
def printf(s):
print(s.format(**globals()))
for NR, line in enumerate(sys.stdin):
match = eval(sys.argv[1])
if match:
eval(sys.argv[2])
Then you can use this in command line as
somecommand | pyawk.py "re.search(r'^(pattern)\s(otherpattern)', line)" "printf('{NR}) {match[1]}')"
I deliberately didn't pass pattern straight into re.search but rather provides the option to do other forms of parsing/matching in that argument, for example json parsing. I just spent 2 minutes writing this script so it's obviously not perfect and you probably won't be able to use it for json out of the box but give it a few more iterations and it will most likely work.