The computer is being a computer: it's doing what you told it to do instead of what you wanted it to do.
grep -v "something something"
prints all lines that do not contain something something
. For example, it prints two lines among the following three:
hello world
this is something something
something else
To print files that do not contain extends SomethingSomething
anywhere, use the -L
option:
grep -L -E 'extends[[:space:]]+SomethingSomething' FILENAME…
Some versions of grep do not have the -L
option (it is not specified by POSIX). If yours doesn't, have it print nothing, and use the return code to have the calling shell do whatever it should do instead.
grep -q -E 'extends[[:space:]]+SomethingSomething' FILENAME ||
echo "$FILENAME"
Alternatively, use awk.
awk '
FNR == 1 && NR != 1 && !found { print fn }
FNR == 1 { fn = FILENAME; found = 0; }
/extends[[:space:]]+SomethingSomething/ { found = 1 }
END { if (fn != "" && !found) print fn }
'
On Linux or Cygwin (or other system with GNU grep), you don't need to use find
, as grep
is capable of recursing.
grep -R --include='*.java' -L -E 'extends[[:space:]]+SomethingSomething'
If your shell is ksh or bash or zsh, you can make the shell do the filename matching. On bash, run set -o globstar
first (you can put this in your ~/.bashrc
).
grep -L -E 'extends[[:space:]]+SomethingSomething' **/*.java