-3

For example, filenames.csv contains a list of product codes PROD111, PROD222, ... that partially match file names in a folder: PROD111a.jpg, PROD111b.jpg, ... How would i copy the files that match into a new folder?

jww
  • 97,681
  • 90
  • 411
  • 885
Mark Webb
  • 9
  • 3
  • I did read through the Tour page and searched for a solution before posting. Sorry if my question offends, I didn't think it would be that complicated. The closest solution I found was only with exact matches: xargs -a filenames.csv cp -t newfolder – Mark Webb Jun 03 '18 at 02:10

1 Answers1

0
#!/bin/bash
file1="filename.txt";
source="./" 
dest="./subfolder/"; 

for i in $(cat $file1); do
    for j in $(ls | grep $i);do
            cp -prf "$source$j" "$dest";
    done;
    echo "Copied all files starting with : $i";
done;
Mark Webb
  • 9
  • 3