How to Find a string in multiple files

February 13, 2011 at 10:00:12
Specs: Windows Vista
Hi Every One,

I am trying to find a particular string in multiple files but i am not able to resolve the below issue.

FOR /F %%i in (FILELIST.TXT) do (
FOR /L %%N in (1,1,2) do (
SET STR1="TEXT"
SET STR2="TEXT1"
FINDSTR /C:%STR%N%% %%i
IF %ERRORLEVEL%==0 (
ECHO %%i
ECHO STR%N%
ECHO TEXT FOUND
)
IF %ERRORLEVEL%==1 (
ECHO TEXT FOUND
)
)

Filelist.txt contains list of all the file which are in that particular folder.

O/P which i expect should like that File1 Contain TEXT and File2 contain TEXT1
File1.TXT
STR1
TEXT FOUND
File2.TXT
STR2
TEXT FOUND
--------------------------------------------------------------
Additional detail

I have Two String which i want to find in all the files present in a particular folder if String found then display filename with message TEXT FOUND


See More: How to Find a string in multiple files

Report •


#1
February 13, 2011 at 13:19:56
try below...this is something similer i answered today itself for someone else

==============================================================

@echo off & color a & setlocal enabledelayedexpansion & cls

:: taking list of text files in files.txt
dir /b | findstr /i /v "bat files" >files.txt
::setting strings as variblals.
set STRN1="ROB MARTIN"
set STRN2="STONE CLOD"
echo.Strings to be search for are - %STRN1% %STRN2%
for /f %%i in (files.txt) do (
echo Searching in file %%i
FOR /L %%N in (1,1,2) do (
echo searching for !STRN%%N!
findstr /i /c:!STRN%%N! %%i
if !errorlevel!==0 echo text found

if !errorlevel!==1 echo text not found


)

pause

)


====================================================
let us know incase question

Subhash Chandra.
www.s-chandra.co.cc


Report •
Related Solutions


Ask Question