Pipe find into grep -v

findgreppipe

I'm trying to find all files that are of a certain type and do not contain a certain string. I am trying to go about it by piping find to grep -v

example:

find -type f -name '*.java' | xargs grep -v "something something"

This does not seem to work. It seems to be just returning all the files that the find command found. What I am trying to do is basically find all .java files that match a certain filename(e.g. ends with 'Pb' as in SessionPb.java) and that do not have an 'extends SomethingSomething" inside it.

My suspicion is that I'm doing it wrong. So how should the command look like instead?

Best Answer

There is no need in xargs here. Also you need to use grep with -L option (files without match), cause otherwise it will output the file content instead of its name, like in your example.

find . -type f -iname "*.java" -exec grep -L "something somethin" {} \+