Windows 'findstr' command: Exclude results containing particular string

32,780

Solution 1

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.

Solution 2

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

Share:
32,780
Subway
Author by

Subway

Updated on July 09, 2022

Comments

  • Subway
    Subway almost 2 years

    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?

  • Tomasz Gandor
    Tomasz Gandor over 7 years
    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 "..."