I'm looking for a program to use an external program to filter the lines of a stream - pretty much a version of
grep that, for each line, prints or suppresses it based on whether the specified program exits with a zero exit code (like
I know that I can do this in shell by using a loop and a subshell:
some-program |(while read line; do if predicate "$line"; then echo "$line" fi done)
What I'm wondering is if there's a program floating around that will let me make this simpler:
some-program |filter predicate # want negation as well some-program |filter ! predicate
One would think that an enhanced Sed might support this, asking "does it pass on the pattern space?", but GNU Sed does not seem to have such a facility.
Is there such a program somewhere that I haven't found, or do I just need to do it in shell (or perl)?