user2553264
user2553264

Reputation: 69

Search a directory and all files within for a certain string

Hello I'm very new to dos, but I need a batch file that searches through all files in a directory for a certain string and copy those lines to a new file.

FOR /R %%G IN (*) DO FIND "string" C:\ "%%G" > result.txt

But I can't get it to work

Upvotes: 1

Views: 220

Answers (2)

Aacini
Aacini

Reputation: 67216

findstr /N "string" *.* > result.txt

Upvotes: 0

npocmaka
npocmaka

Reputation: 57252

this worked for me through the command prompt:

for /r %G in (*) do @find "import" "%~G" >nul 2>&1 && @echo %G

EDIT: To see lines and numbers:

for /r %G in (*) do @findstr /n "issue" "%~G"  2>null && @echo %G

Upvotes: 2

Related Questions