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\\"
Author by
Subway
Updated on July 09, 2022Comments
-
Subway almost 2 years
To the command
findstr str1 *.*
I want to add something that will exclude the results which contain the stringstr2
.In Linux the way of doing it is to add
| grep -v str2
(togrep str1 *
of course). Is there an equivalent flag to-v
in Windows? -
Tomasz Gandor over 7 yearsWow! 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 ofwcgrep
, by usingfindstr /S "needle" * | findstr /V "..."