How to check for text in a text document

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

How to check for text in a text document

#1 Post by Rileyh » 06 Oct 2011 22:59

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

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

Re: How to check for text in a text document

#2 Post by aGerman » 07 Oct 2011 15:17

Code: Select all

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


Regards
aGerman

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: How to check for text in a text document

#3 Post by Rileyh » 08 Oct 2011 01:05

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

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

Re: How to check for text in a text document

#4 Post by aGerman » 08 Oct 2011 08:51

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

Post Reply