I've been very frustrated at repeatedly finding this answer to this question, which is in fact completely unhelpful.
Using -v will return 0 for any file that contains lines that don't contain the search pattern, which is generally true, and therefore generally useless!
The 'real' answer IMHO is that you need to do this using your OS/shell to reverse the return code. On Win32 >Win2k you can use this:
cmd /c "grep pattern $< & if not ERRORLEVEL 1 exit 1"
I imagine that on unix shells this should be simpler and less cryptic, but will leave that to someone more expert than myself to comment on should they care.
Comment