I m piping some output of a command to egrep, which I m using to make sure a particular failure string doesn t appear in.
The command itself, unfortunately, won t return a proper non-zero exit status on failure, that s why I m doing this.
command | egrep -i -v "badpattern"
This works as far as giving me the exit code I want (1 if badpattern appears in the output, 0 otherwise), BUT, it ll only output lines that don t match the pattern (as the -v switch was designed to do). For my needs, those lines are the most interesting lines.
Is there a way to have grep just blindly pass through all lines it gets as input, and just give me the exit code as appropriate?
If not, I was thinking I could just use perl -ne "print; exit 1 if /badpattern/". I use -n rather than -p because -p won t print the offending line (since it prints after running the one-liner). So, I use -n and call print myself, which at least gives me the first offending line, but then output (and execution) stops there, so I d have to do something like
perl -e $code = 0; while (<>) { print; $code = 1 if /badpattern/; } exit $code
which does the whole deal, but is a bit much, is there a simple command line switch for grep that will just do what I m looking for?