0

I tried to write a batch script to do the below task

I have list of 1000 unique Employee IDs (numerical IDs, no. of digits may differ) in a text file called empids.txt. And also I have folder called MasterIDs which contains multiple text files and each text file has 100 thousand IDs

I tried a batch script to search the 1000 IDs listed in the empids.txt and show the whether any listed ids are present in the multiple textfiles in the MasterIDs folder. The expected result is like the below

expected output

  • 12345678 is found in *.txt
  • 1145897 is not found

below is the batch script i tried and I am not getting the expected output. It just searches and give the whole line which contains the searched string.

set manifest_folder=\\vfiler-padhu\padhu\*.txt
set file_list=\\vfiler-padhu\padh\File_list.txt
set tmpFile=\\vfiler-padhu\padh\tmpFile.txt
for /f "delims=" %%f in (%file_list%) do (
findstr /L  %%f %manifest_folder% >> %tmpFile%
) 
pause

I am just started learning batch script. Kindly help to do this task.

2
  • Do you need the name of the file where the id is found or only to know it has been found? Commented Aug 20, 2014 at 10:49
  • I need the file name also.. like 1234567 is found in *.txt Commented Aug 20, 2014 at 10:50

1 Answer 1

1
@echo off
setlocal enableextensions disabledelayedexpansion

set "manifest_folder=\\vfiler-padhu\padhu\*.txt"
set "file_list=\\vfiler-padhu\padh\File_list.txt"
set "tmpFile=\\vfiler-padhu\padh\tmpFile.txt"

    (for /f "usebackq delims=" %%a in ("%file_list%") do (
        set "found="
        for /f "delims=" %%b in ('findstr /l /m /c:"%%a" "%manifest_folder%"') do (
            echo %%a is found in %%~nxb
            set "found=1"
        )
        if not defined found (
            echo %%a is not found
        )
    )) > "%outputFile%"

This will read input file and for each line/id a search in the manifest folder is executed, asking for the name of the files where the id is found.

Sign up to request clarification or add additional context in comments.

1 Comment

Works great. Thank you. Marked as answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.