Rez88
Rez88

Reputation: 49

Search for a specific string in a list of files located in a directory Batch Scripting

how would look for a specific string in a list of files in a given directory using batch? For example the following string RTW4OTO150227074405851I2631911150227CAC.

I Have tried this but it is not working:

for %%f in (payment.*) do findstr /i /m /p /c:"RTW4OTO150227074405851I2631911150227CAC" "%%f"" >> results.txt 

Upvotes: 0

Views: 209

Answers (3)

Soheil
Soheil

Reputation: 837

you can use fnr find string you want support regex plus you can recurse search all sub directory search for specific string then change to any thing you want it example

.\fnr.exe --cl --dir "c:\" --filemask "*.txt" --find "hi" --replace "bye" --includeSubDirectories

or

dir c:\ /a/b | findstr "RTW4OTO150227074405851I2631911150227CAC" >1.txt

Upvotes: 0

dbenham
dbenham

Reputation: 130819

There is no need for a FOR loop:

findstr /i /m /p /c:"RTW4OTO150227074405851I2631911150227CAC" payment.* >results.txt 

Upvotes: 1

Ryonite
Ryonite

Reputation: 55

If Powerhsell is an option you can try

Get-ChildItem -Path C:\Myfolder -Filter RTW4OTO150227074405851I2631911150227CAC -Recurse

Upvotes: 0

Related Questions