Page 1 of 1

How to check for text in a text document

Posted: 06 Oct 2011 22:59
by Rileyh
Hi all,
I would like to know how to check for text in a text document.
Eg:
(in text document) Hello World!

And then the batch file would do something like:
if exist "hello world" (do whatever)

Could someone do that? If so then could you tell me the code to do so?

Any help would be appreciated,
Rileyh

Re: How to check for text in a text document

Posted: 07 Oct 2011 15:17
by aGerman

Code: Select all

findstr /ic:"hello world" "test.txt" >nul &&(
  REM your code here
)


Regards
aGerman

Re: How to check for text in a text document

Posted: 08 Oct 2011 01:05
by Rileyh
aGerman,
I think that either their is an error with your code or my code because I copied and pasted your code into my existing code and it didn't work.
Here is my code. Hopefully you can (from looking at my code) see what I am trying to do:

Code: Select all

@echo off
findstr /ic:"print" "test.txt" >nul &&(
)
echo It worked.
pause <nul
goto :eof
:b
echo It worked.
pause >nul


Do you see what I am trying to do.
If not, post a reply.

Regards,
Rileyh

Re: How to check for text in a text document

Posted: 08 Oct 2011 08:51
by aGerman
The REM line is only a remark/comment. You have to replace it with your code which should be executed if "print" was found in "test.txt".

Regards
aGerman