I want to inject a command into a pipeline that just validates the input at that point, passing it on if it's valid. If it isn't valid nothing could be passed on, or perhaps a custom-defined error message from an option or something.
At the moment I'm using perl for this as in this example where I check for an expected unique match for $1 in a file:
grep -P '^\s*\Q$(strip $1)\E\s+' file_codes.txt \
| perl -e '@in = <STDIN>;' \
-e '@in == 1 or die "wrong number of matches";' \
-e 'print @in' \
| xargs \
| ...
I don't like this because it seems both un-pipeish and un-perlish with the explicit read and print involving @in. It seems like there out to be something like tee or so that does it but I didn't find it.