Open JJK96 opened 2 years ago
Maybe replace the regexes in the string by re.match(r"<regex>", ...)
. Then later eval it as an expression.
Would this do what you want?
cat /etc/hosts | pawk '!/^#|^127/'
In this example, yes, but I think a general solution is useful, because sometimes you want to make it match 2 regexes after each other with an and
relation. Example:
$ cat meetings
Bob meets Alice
Charlie meets Dave
Dave meets Alice
Alice meets Bob
$ cat meetings | pawk '/Bob/ and /Alice/'
Alice meets Bob
Bob meets Alice
Awk allows this with the &&
operator:
cat meetings.txt | awk '/Bob/&&/Alice/'
Alice meets Bob
Bob meets Alice
Why not just run it through pawk twice?
$ cat meetings.txt | pawk '/Bob/' | pawk '/Alice/'
it's only a few characters longer than the syntax you're suggesting
At the moment I can't think of a good example, I'll get back to it if I encounter one. Thanks for the suggestions and for making this tool!
Feature request to enable things like:
cat /etc/hosts | pawk '!/^#/ and !/^127'
This would require a whole new way of parsing. It should parse it as a python expression with some syntactic sugar for regex matches.