Search code examples
batch-filefindstr

bat file that findstr string1 AND string2


I am trying to do the following: Search through all txt file in Temp that starts with 'Micro' and find if the following two strings exists in any of them. I need to find both strings in 1 file.

Currently I've got:enter code here

@echo off
cd C:\Users\ADMINI~1\AppData\Local\Temp
findstr /N /C:"action: Uninstall" /C:"Exit code: 0x0, restarting: No" Micro*.log >results.txt
if %errorlevel%==1 (
robocopy C:\Users\ADMINI~1\AppData\Local\Temp C:\Users\Administrator\Desktop results.txt
) else (
echo matches found
)

but this is using OR. I found that I need to use .* for AND, but the following simple doesn't work:

findstr /N /C:"action: Uninstall".*/C:"Exit code: 0x0, restarting: No" Micro*.log

not sure what I'm doing wrong. :/

Cheers, Geri


Solution

  • set "string1=action: Uninstall"
    set "string2=Exit code: 0x0, restarting: No"
    set "files=C:\Users\ADMINI~1\AppData\Local\Temp\Micro*.log"
    
    findstr /m /c:"%string1%" "%files%" | findstr /f:/ /m /c:"%string2%"
    

    Get the list of files that contain the first string and use this list to search the second string.