Page 1 of 1

question about the "find" command

Posted: 26 Nov 2013 03:53
by AiroNG
Is there a way to let "find" only display files were the string was found intead of display every searched file?

Example:

Code: Select all

find "text" *.txt

Result:

Code: Select all

---------- README.TXT

---------- TEST.TXT
text

---------- HIT.TXT
text

---------- SNIPPETS.TXT


I'm only interested in this:

Code: Select all

---------- TEST.TXT
text

---------- HIT.TXT
text

Re: question about the "find" command

Posted: 26 Nov 2013 04:16
by Sponge Belly
Hi AiroNG, :-)

The findstr command will do what you want:

Code: Select all

findstr /l "text" "*.txt"


It will output only the filenames that contain the matching text. Read findstr’s help for more info. There are many switches to be mastered.

Good luck! ;-)

- SB

Re: question about the "find" command

Posted: 26 Nov 2013 04:18
by foxidrive
This displays the filename under the found text.

Code: Select all

for %%a in (*.txt) do find "text" < "%%a" && echo  ----------   %%a


You could save each files output and type it after the echo statement, if you need the filename above the beginning of the text.

Re: question about the "find" command

Posted: 26 Nov 2013 06:03
by AiroNG
@Sponge Belly & @foxidrive
Thanks. Both of your answers do help me a lot!