question about the "find" command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

question about the "find" command

#1 Post by AiroNG » 26 Nov 2013 03:53

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

Sponge Belly
Posts: 216
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: question about the "find" command

#2 Post by Sponge Belly » 26 Nov 2013 04:16

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: question about the "find" command

#3 Post by foxidrive » 26 Nov 2013 04:18

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.

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: question about the "find" command

#4 Post by AiroNG » 26 Nov 2013 06:03

@Sponge Belly & @foxidrive
Thanks. Both of your answers do help me a lot!

Post Reply