osx - Shell Script Find and Copy from txt file -


i'm wanting read line line text file recursively find files in target folder. if found copy file directory. script below executes doesn't perform find or copy when running sh script.sh terminal. no errors displayed, echo $line variable string correctly each loop iteration. running same find terminal using actual filename instead of $list variable complete task successfully.

script:

script.sh #!/bin/bash file="filenames.txt" while ifs= read line find /volumes/share/all-files-location -name "$line" -print -exec cp {} /volumes/share/found-files-location \; done < "$file" 

list of file names, plain text:

a1037_mg_1262.jpg a1037_mg_12621.jpg a1037_mg_1263.jpg [11,000 more entries] 

thoughts?

since input file in crlf, , unix uses lf line ending, bash script sorting lines occurrence of lf character, , consequently each of filenames had \r appended end of it. since disk didn't contain filenames containing \r, find tool didn't find of files, result being tool appeared fail no error message given.

solution: switch file's line ending format lf.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -