Your code does not contain lines to search in the given directory and compare the files inside that directory with the given files (req_files.txt). All you do is keep on overwriting (since you are using >
operator, use >>
to append instead) the file a.txt with contents of req_files.txt one by one and when the script finishes running, you are left with only the last item written to a.txt.
As per my understanding, your goal is:
Search and list all the files inside that given path. Then compare that list with the files listed in req_files.txt. And finally, list the matching ones in the output file a.txt. In that case, below code does it for you:
cwd=/cygdrive/c/Users/abhisek.samanta/Desktop/New_folder
cd $cwd #change dir to the required path
>a.txt # create output file a.txt
for file in `ls`:
do
grep "`echo "$file"`" req_files.txt >> a.txt
done
In for loop, you are now listing the files using ls command. This script will create a file a.txt inside the given path which contains the files from req_files.txt that are present in that given path.