DOS batch file to list used variabl

February 21, 2009 at 06:25:31
Specs: Windows XP
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


See More: DOS batch file to list used variabl

Report •


#1
February 21, 2009 at 07:25:11
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


Report •

#2
February 21, 2009 at 07:35:10
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.

Report •

#3
February 21, 2009 at 08:02:25
R2,

LOL


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

M2


Report •

Related Solutions

#4
February 22, 2009 at 01:52:35
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)

Report •

#5
February 23, 2009 at 02:58:23
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.)

Report •


Ask Question