20

To the command findstr str1 *.* I want to add something that will exclude the results which contain the string str2.

In Linux the way of doing it is to add | grep -v str2 (to grep str1 * of course). Is there an equivalent flag to -v in Windows?

Subway
  • 5,286
  • 11
  • 48
  • 59

2 Answers2

27

Is there an equivalent flag to -v in Windows?

The equivalent to -v is /V.

C:\Users\Todd>findstr /?
Searches for strings in files.

...

/V         Prints only lines that do not contain a match.
ta.speot.is
  • 26,914
  • 8
  • 68
  • 96
11

use /V, for example: findstr "hello world" *.cpp | findstr /V ".git\\"

1lOtzM291W
  • 450
  • 6
  • 10
  • Wow! I just discovered you need the double backslash, `".git\"` doesn't work. The only downside is, the filenames are not highlighted anymore :( I now have a replacement of `wcgrep`, by using `findstr /S "needle" * | findstr /V "..."` – Tomasz Gandor Oct 20 '16 at 08:32