Terry-Crunchbang
Terry-Crunchbang

Reputation: 21

Shell script to use a list of filenames in a CSV to copy files from one directory to another

I have a list of files that I need to copy. I want to recursively search a drive and copy those files to a set location if that filename exists in the list. The list is a text file/

the text file would look something like this:

A/ART-FHKFX1.jpg
B/BIG-085M.jpg
B/BIG-085XL.jpg
L/LL-CJFK.jpg
N/NRT-56808EA.jpg
P/PFE-25.10.jpg
P/PFE-7/60.jpg
P/PFE-7L.20.jpg
P/PFE-8.25.jpg
P/PFE-9.15.jpg
P/PFE-D11.1.tiff
P/PFE-D11.1.tiff
P/PFE-D12.2.tiff
P/PFE-D12.2.tiff

Upvotes: 2

Views: 2743

Answers (1)

Samus_
Samus_

Reputation: 2993

using find will take a lot of time, try to use locate if possible.

what will happen when there's several matches? like searching for foo.bar and having a/foo.bar and also b/foo.bar what would you do in that case?

your csv seems to include a path, given the previous I'll assume those paths are actually valid from where the script is run so in that case just do this:

#!/bin/bash

while read path; do
    cp "$path" "$1"
done

then call it like this:

teh_script /path/to/destination < csv-file.csv

Upvotes: 2

Related Questions