Computing.Net > Forums > Programming > DOS batch file to list used variabl

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.

DOS batch file to list used variabl

Reply to Message Icon

Name: rameshK
Date: February 21, 2009 at 06:25:31 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

I am developing a script using MSDOS batch files for searching for strings in a directory
My requirement is as follows
I have a text file with a set of labels
I have to search if each label is used in any one of the files present in the directory
If its used in any one of the files, then i should be log it in the used variables.txt
If a variable is not used in any file, then i should log it in notused.txt

example
Input text file input.txt contains the following data
label1
label3
label5

in the source directory there are 2 files a.txt and b.txt
the contents of a.txt is

label1: uses label1

the contents of b.txt is

label5: uses label5

when i run my batch file i should get 2 files as output
usedvariables.txt that contains
label1
label5
and notused.txt that contains
label3

I am using MSDOS 5.0 and i am unable to get it using the find command
Code used enclosed.

@echo on
del found.txt
del notfound.txt
for /f "delims=" %%i in (input.txt) do (
call :chkscript.bat %%i

)


:chkscript.bat
SET name=%~1
FOR /f "delims=" %%q IN ('dir /b C:\temp\') DO (
FIND "%name%" /C /I %%q
IF %ERRORLEVEL% == 0 CALL :found %name%
PAUSE
)
:notfound
rem echo %name%>>notfound.txt
ECHO Name not found"
GOTO :EOF

:found
echo %~1>>found.txt
GOTO :EOF



Sponsored Link
Ads by Google

Response Number 1
Name: reno
Date: February 21, 2009 at 07:25:11 Pacific
Reply:

for /f %%a in (input.txt) do (
find /i "%%a" *.txt >nul 2>&1 && (echo found %%a) || (echo not found %%a)
)

tested on winxp cmd, not sure about msdos5.0


0

Response Number 2
Name: Razor2.3
Date: February 21, 2009 at 07:35:10 Pacific
Reply:

I am using MSDOS 5.0
Seriously? Then your script has a lot of issues.

    @echo on                                            -- Valid :)
    del found.txt                                       -- Valid :)
    del notfound.txt                                    -- Valid :)
    for /f "delims=" %%i in (input.txt) do (            -- Invalid :(
    call :chkscript.bat %%i                             -- Invalid :(
                                                        -- Valid :)
    )                                                   -- Invalid :(
                                                        -- Valid :)
                                                        -- Valid :)
    :chkscript.bat                                      -- Valid :)
    SET name=%~1                                        -- Technically valid :/
    FOR /f "delims=" %%q IN ('dir /b C:\temp\') DO (    -- Invalid :(
    FIND "%name%" /C /I %%q                             -- Technically valid :/
    IF %ERRORLEVEL% == 0 CALL :found %name%             -- Invalid :(
    PAUSE                                               -- Valid :)
    )                                                   -- Invalid :(
    :notfound                                           -- Valid :)
    rem echo %name%>>notfound.txt                       -- Valid :)
    ECHO Name not found"                                -- Valid :)
    GOTO :EOF                                           -- Invalid :(
                                                        -- Valid :)
    :found                                              -- Valid :)
    echo %~1>>found.txt                                 -- Technically valid :/
    GOTO :EOF                                           -- Invalid :(

That's 13 valids to 24 total lines. Almost half (or more than half, if you remove the blank lines) of that script won't work in true MS-DOS.

0

Response Number 3
Name: Mechanix2Go
Date: February 21, 2009 at 08:02:25 Pacific
Reply:

R2,

LOL


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Judago
Date: February 22, 2009 at 01:52:35 Pacific
Reply:

This is just nitpicking but wouldn't "goto :eof" class as "Technically valid :/" provided that the script has a label called :eof? (I can see that it doesn't)


0

Response Number 5
Name: Razor2.3
Date: February 23, 2009 at 02:58:23 Pacific
Reply:

Judago: This is just nitpicking but wouldn't "goto :eof" class as "Technically valid :/" provided that the script has a label called :eof?
Had he an :EOF, then it'd be valid, yes. As written, however, the GOTO will throw an error. And yes, which is my classification for the invalid lines. (Technically valid are lines I don't think will throw an error, but won't do/give him what he wants.)


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: DOS batch file to list used variabl

Batch file to list dir name www.computing.net/answers/programming/batch-file-to-list-dir-name-/17362.html

Batch file to check a directory is www.computing.net/answers/programming/batch-file-to-check-a-directory-is-/17337.html

DOS batch file to read newest text file www.computing.net/answers/programming/dos-batch-file-to-read-newest-text-file/19729.html