I'd use awk for this:
pw-cli list-objects | awk '/node\.name/ && /output/ && /pci/ && /analog/'
Or maybe perl if I needed perl's regex syntax, or other perl language features or library modules (neither of which are actually needed for this example):
pw-cli list-objects |
perl -n -e 'print if (/node\.name/ && /output/ && /pci/ && /analog/)'
There are two main benefits in using awk or perl for this:
it will match input lines regardless of the order of words in the input. i.e. a regex like node\.name.*output.*pci.*analog
will match only if those words are in the input line in exactly that order. The awk or perl one-liners above will match if ALL four words are present anywhere in the input line, in any order - this is equivalent to the way you've chained multiple grep
s together in the pipeline.
You could use extended regexps with alternations (|
) for every placement variation, but with four words, you'd need 16 alternate versions to match every possible arrangement, so that's kind of impractical - (a.*b.*c.*d)|(a.*c.*b.*d)|(a.*b.*d.*c)|.........
You can use any combination of &&
(AND), ||
(OR), !
(negation), and parentheses to construct an arbitrarily complex boolean conditional. You can also combine with any other awk or perl syntax that returns a true or false result (e.g. calculations & comparisons based on fields within the input line).