Search for EXACT word using a Batch file - Help!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Search for EXACT word using a Batch file - Help!

#1 Post by val5662 » 29 Apr 2017 12:49

I have a folder with one hundred and some htmls.I want to find an exact match to any complete word I search for and display it in a text file.The latest attempt still failed:

for %%f in (*.html) do findstr /m /p /c:"cop.rar" "%%f" >> exact-results.txt

What the above only does is shows the results of the name.html files that the word cop is in.
Examples it found: 69cop.rar , 75cop.rar , lastcop.rar , anothernamecop.rar
No good....what I want is the EXACT word only that I search for.
If I search for cop.rar , I only want the name of the html(s) that cop.rar would be in.Thanks for your help!
Val

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Search for EXACT word using a Batch file - Help!

#2 Post by aGerman » 29 Apr 2017 13:22

Use regular expressions (option /r) and word boundaries.

Code: Select all

findstr /rmpc:"\<cop\.rar\>" "%%f"


Steffen

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Re: Search for EXACT word using a Batch file - Help!

#3 Post by val5662 » 29 Apr 2017 15:47

Steffen...
Thanks! I appreciate it a bunch.This works like a charm!

for %%f in (*.html) do findstr /rmpc:"\<cop\.rar\>" "%%f" >> found-xact-complete-name.txt

Problem solved... :D

Val

Post Reply