bindiego
6/3/2015 - 7:18 AM

1. load file names into an array 2. get local file paths 3. cp files into targeting folder if local file exists in the file names array

  1. load file names into an array
  2. get local file paths
  3. cp files into targeting folder if local file exists in the file names array
#!/bin/bash -

set -o nounset                              # Treat unset variables as an error
pwd=$(pwd)

# clearing up the targeting directory
target=${pwd}/target
[ -d ${target} ] && rm -rf ${target}

mkdir -p ${target}

# set the delimiter
IFS='
'

# get all file names
filenames=$(< filenames.csv)
#for filename in ${filenames[@]}
#do
    #echo ${filename}
#done

# get all file paths
files=$(find . -name "*.doc*")
for file in ${files[@]}
do
    #echo ${file}
    for filename in ${filenames[@]}
    do
        if [[ ${file} == *"${filename}"* ]]
        then
            cp -a ${file} ${target}
        fi
    done
done