Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Windows batch script check if a csv value exist in another csv file

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading