Test conditions
Two files (devinfo.txt, test.bat ) are need to present in the same folder, something look like this c:\test\
devinfo.txt'contents, pls take a note that this file is generated by external cmd with 'devcon.exe status * > devinfo.txt'
ACPI\INT33BB\2
Name: Intel SD Host Controller
Driver is running.
ACPI\INT9918\1
Name: SARProximity Device
Driver is running.
ACPI\INT33BD\1
Name: Intel(R) Sideband Fabric Device
Driver is running.
ACPI\INT3406\2&DABA3FF&1
Name: Intel(R) Dynamic Platform & Thermal Framework Display Participant Driver
Driver is running.
ACPI\NXP5442\1
Device has a problem: 28.
ACPI\80860F0E\2&DABA3FF&1
Name: SPI Controller
Driver is running.
ROOT\SYSTEM\0000
Name: Plug and Play Software Device Enumerator
Driver is running.
ROOT\SYSTEM\0001
Name: IWD Bus Enumerator
Driver is running.
HID\INTCFD9&COL01\3&2B7A34A4&0&0000
Name: HID Keyboard Device
Driver is running.
ROOT\RDPBUS\0000
Name: Remote Desktop Device Redirector Bus
Driver is running.
ACPI\80860F14\1
Name: Intel SD Host Controller
Driver is running.
ACPI\80860F14\3
Name: Intel SD Host Controller
Driver is running.
USB\ROOT_HUB30\4&84243BB&0&0
Name: USB Root Hub (xHCI)
Driver is running.
HID\SMO91D0&COL01\4&1D42B6AD&0&0000
Name: HID Sensor Collection
Driver is running.
ACPI\10EC5640\1
Name: Realtek I2S Audio Codec
Driver is running.
ACPI\PNP0100\4&A8408E&0
Name: System timer
Device is currently stopped.
16 matching device(s) found.
test.bat is as below
@echo off setlocal enabledelayedexpansion ::变量延迟开启,for语句 REM devcon.exe status * >devinfo.txt for /f "delims=: tokens=1,*" %%i in ('findstr /n /c:"Device has a problem" devinfo.txt') do (
rem 343: Device has a problem: 28. this is separated by ":", %%i is 343, %%j is Device has a problem: 28. echo %%j>>result.txt set flag=1 set line=%%i call :twoline ) goto :eof :twoline REM Two lines need to be searched, like ''ACPI\NXP5442\1 REM Device has a problem: 28 set /a line=line-1 for /f "tokens=1,* delims=:" %%i in ('findstr /n .* devinfo.txt') do ( rem search from full log, also delimited by ":"
if %line% equ %%i ( echo %%j>>result.txt if %flag% ==1 ( rem iteration once
set flag=0 goto :twoline ) else (goto :eof) ) )
output with being:
Device has a problem: 28
ACPI\NXP5442\1
Driver is running