I have developed a script to check if a value exists from one CSV file against another CSV file. I need to automate the script to read one csv file with hostname values against another logging csv file.
echo %date% %time% Starting Program
echo -----------------------------------------------------------------------------------------------------------------
echo Checking files
echo -----------------------------------------------------------------------------------------------------------------
FOR /F "tokens=2" %%i in ('date /t') do set mydate=%%i
set mytime=%time%
echo Performing Magic ...
echo -----------------------------------------------------------------------------------------------------------------
for /f "tokens=3" %%i in ('find /C "TEST01" logging.csv') do (
if [%%i]==[1] (
echo TEST01 was NOT found
) else (
echo The device TEST01 is logging ...
)
)
The code works correctly but I would like to be able to read a hostname.csv file and use the value as a iterator instead of having to hardcode "TEST01" which is the hostname.
I have not been able to add a iterator to be read and not have to hardcode the hostname in the file. Having to hardcode each name will make the code very long. The hostname.csv file has several hostnames in it.
>Solution :
for /f %%s in (yourfilename) do (
for /f "tokens=3" %%i in ('find /C "%%s" logging.csv') do (
if [%%i]==[1] (
echo %%s was NOT found
) else (
echo The device %%s is logging ...
)
)
)
should solve your problem, where yourfilename contains
TEST01
TEST02
TEST03