1.

Solve : find command?

Answer»

I WANT to find a string in file and PROMPT message if the count is >0.

find "Hello" "C:\test.dat"

but this command outputs file name and number of occurance. how to CAPTURE number of occurance in script???check the errorlevel, i think this is the right way round:

Code: [Select]find "Hello" "C:\test.dat">nul
if errorlevel 0 echo message here
FBQuote from: fireballs on January 29, 2009, 08:28:12 AM

check the errorlevel, i think this is the right way round:

Code: [Select]find "Hello" "C:\test.dat">nul
if errorlevel 0 echo message here
FB

but...

Quote
how to capture number of occurance in script???

But...

Quote from: rao on January 29, 2009, 08:13:59 AM
I want to find a string in file and prompt message if the count is >0.

I read the original POST as MEANING the above, and capturing the occurances as an after thought to stop the output appearing on screen. I guess the OP can clear this up.

FBYup you're right, the OP asked 2 different questions.

By the way in Windows 200 and later these work

Code: [Select]find "Hello" "C:\test.dat">nul && echo hello is present in the file
Code: [Select]find "Hello" "C:\test.dat">nul || echo hello is not present in the file
to get the count is slightly more complex and the OP should please say if that is what he or she wants.



Discussion

No Comment Found