Solved To Read a Word in a Text file as Input to a batch file

March 22, 2013 at 08:59:25
Specs: Windows XP
Thanks in advance for your valauble inputs.

I need to check if the word "Myself" is in the text file 1.txt and print "Done" if it is found, else print fail if it is null or different.

My 1.txt file looks like this
---------
Myself 123456 is not
much complicated
---------

I did this with two batch files.
1.bat:
----------------
@setlocal
%v% = findstr myself:D:\script\1.txt
D:\script\2.bat %v% > D:\script\log.txt
endlocal
----------------
2.bat:
-----------------
@setlocal enableextensions enabledelayedexpansion
@ECHO OFF
ECHO.
set str=%1
IF "%str%"=="" ECHO Failed
IF "%str%"=="Myself" ECHO DONE
IF NOT "%str%"=="Myself" ECHO Failed
endlocal
-----------------

Aravind


See More: To Read a Word in a Text file as Input to a batch file

Report •


#1
March 22, 2013 at 11:08:19
✔ Best Answer
@echo off
set /p phrase="PLease enter the search phrase (case sensitive) : "
FindStr /R %phrase% 1.txt 
cls
If %ERRORLEVEL% EQU 0 echo The string %phrase% is Present
If %ERRORLEVEL% EQU 1 echo The string %phrase% is not Present
pause

:: mike


Report •

#2
March 25, 2013 at 01:55:10
Thanks a lot Mike... it works...

Report •

#3
March 26, 2013 at 02:53:05
it's ok. For other people,
just do
findstr /v /b /c:" " <file.txt



Report •

Related Solutions

#4
March 26, 2013 at 08:40:59
IT looked like there was a need for a response of found or not found...not just the line it was on. My apologies for apparently over complicating things.

:: mike


Report •


Ask Question