The findstr documentation of Microsoft is indeed not the best. The SS64 documentation for findstr is much better and contains the section Default type of search: Literal vs Regular Expression explaining when FINDSTR runs by default a literal and when a regular expression find if not explicitly defined with /L
for literal OR /R
for regular expression.
There are several solutions for this task to match only entire lines case-sensitive as by default which can be changed to case-insensitive with /I
.
The first one was given already by apandit.
%SystemRoot%\system32\findstr.exe /R /C:"^test$" test.txt
This runs a regular expression find which matches and outputs only lines containing just the word test
case-sensitive and nothing else as expected.
Another solution also using a regular expression find is
%SystemRoot%\system32\findstr.exe "^test$" test.txt
Yes, without /C:
and because of search string containing the meta-characters ^
and $
, this find is executed as regular expression find.
One more solution would be using a literal find which should output only lines matching entirely the specified search string.
%SystemRoot%\system32\findstr.exe /X /C:"test" test.txt
The same result would produce also this literal search.
%SystemRoot%\system32\findstr.exe /B /E /L /C:test test.txt
The parameter /L
is not really needed because in this case the find is by default literal. But I think, it is good practice to always specify /L
OR /R
to make it clear for FINDSTR as well as for the reader of the command which find is executed: a literal or a regular expression find.