Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :slight_smile:

Lets assume (assume since you have not given complete names and detaios properly)

Your list file name is: img_list.txt whose content is something alike:

111111
222222
333333
444444

Your source directory: /home/user/images/
Your img file names are generally of this form: 11111.jpg
Destination Directory: /home/user/newimages/

#!/bin/bash
 
SRC_DIR=/home/user/images/
I_L_F=<full path to img_list.txt>
DST_DIR=/home/user/newimages/
 
if [[ ! -d "${DST_DIR}" ]]; then
       mkdir -p "${DST_DIR}" ## This will create new directory if not found. 
                                               ## U can either chose to do this or exit at this point. It is just a checkpoint
fi
 
cd  "${SRC_DIR}" 
 
while read imgs; do
    if [[ -f "${imgs}.jpg" ]]; then
           echo "Found ${imgs}.jpg matched with ${imgs} in the list file"
           cp "${imgs}.jpg" "${DST_DIR}" 
    else
        continue
    fi
 
done < "${I_L_F}"