Computing.Net > Forums > Disk Operating System > If statement based on search result

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

If statement based on search result

Reply to Message Icon

Name: cyoulater
Date: December 11, 2007 at 09:41:15 Pacific
OS: DOS
CPU/Ram: 512
Product: Dell
Comment:

I want to create a scenario by which I can query a text file for a certain string and if the string exist then print that the search was successful. I'am writing my first DOS batch program and need some major help. thanks



Sponsored Link
Ads by Google

Response Number 1
Name: worldlibrary
Date: December 11, 2007 at 10:25:21 Pacific
Reply:

I didn't write this....But perhaps it will get you started.

@echo off
if %1.==GOTO. %1 %2
SET FMTEM=%TEMP%
SET FMOUT=%FMTEM%\FINDM.TXT
if not %2.==. goto DO
echo I use FIND.exe /I /N to find a word in a wild-card group of files.
echo Syntax: %0 word filegroup [output_file]
echo Default output file = %FMOUT%
goto END
:DO
SET FMYES=
if not %3.==. set FMOUT=%3
if exist %FMOUT% del %FMOUT%
for %%f in (%2) do call %0 GOTO DO1 %1 %%f
if %FMYES%.==Y. type %FMOUT%
if %FMYES%.==Y. echo %0: Word "%1" occurs in (%2) as listed in %FMOUT%.
if not %FMYES%.==Y. echo %0: Word "%1" was not found in %2.
if exist %FMTEM%\FIND.RPT del %FMTEM%\FIND.RPT
for %%w in (OUT TEM YES) do set FM%%w=
goto END
:DO1
find /N /I "%3" %4 >%FMTEM%\FIND.RPT
if errorlevel 1 goto end
set FMYES=Y
type %FMTEM%\FIND.RPT >>%FMOUT%
:END


0

Response Number 2
Name: worldlibrary
Date: December 12, 2007 at 08:18:02 Pacific
Reply:

This might be a bit simpler. Change BAT to txt and AWK to the string.

You can add all the @echo off ,labels and cls to suite your needs.

for %%f in (*.bat) do find /I "awk" %%f >>find.rpt


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: If statement based on search result

Trying to purge files based on Date www.computing.net/answers/dos/trying-to-purge-files-based-on-date/13804.html

IF command-Batch file help needed! www.computing.net/answers/dos/if-commandbatch-file-help-needed/13047.html

Removing files based on creation date www.computing.net/answers/dos/removing-files-based-on-creation-date/10389.html