Search code examples
batch-filecommandwindows-scriptingfindstr

Windows batch file find string but don't print


I'm new to windows batch scripts but have started using the findstr command e.g.

findstr "test" file.txt
if not errorlevel 1 ( echo Found it!)

The code manages to findtest in file.txt but I don't want it to output the line where it finds "test" I just want it to echo Found it!

Is this possible with findstr or should I be using something else?


Solution

  • Just redirect the output to nul.

    findstr "test" file.txt >nul
    if not errorlevel 1 ( echo Found it!)