Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link
  1. Your loop is incorrect, since you do nothing with rest

  2. As terdonterdon suggested, check after each copy, instead of once after loop

  3. Negate the existence of file check, for correct comment

  4. And heed terdon'sterdon's warning, if you have same named files in your source tree, you will only get one copy in destination.

Try this,

while read -d, -r file
do
   find $sourcefolder -name "${file}" -exec cp '{}' $destfolder \;
   ## Check if the file was copied
   [[ ! -e "$destfolder/$file" ]] && echo "File $file was not copied"
done < "$csv"
echo "Finished"

Update:

This solution works if your CSV is like this

fileA,fileB,fileC,fileD, ...

However since you say terdon's solution works your file must look like this

fileA,valueA1,valueA2,valueA3
fileB,valueB1,valueB2,valueB3
fileC,valueC1,valueC2,valueC3
fileD,valueD1,valueC2,valueD3

and the remainder of line after filename is simply discarded.

  1. Your loop is incorrect, since you do nothing with rest

  2. As terdon suggested, check after each copy, instead of once after loop

  3. Negate the existence of file check, for correct comment

  4. And heed terdon's warning, if you have same named files in your source tree, you will only get one copy in destination.

Try this,

while read -d, -r file
do
   find $sourcefolder -name "${file}" -exec cp '{}' $destfolder \;
   ## Check if the file was copied
   [[ ! -e "$destfolder/$file" ]] && echo "File $file was not copied"
done < "$csv"
echo "Finished"

Update:

This solution works if your CSV is like this

fileA,fileB,fileC,fileD, ...

However since you say terdon's solution works your file must look like this

fileA,valueA1,valueA2,valueA3
fileB,valueB1,valueB2,valueB3
fileC,valueC1,valueC2,valueC3
fileD,valueD1,valueC2,valueD3

and the remainder of line after filename is simply discarded.

  1. Your loop is incorrect, since you do nothing with rest

  2. As terdon suggested, check after each copy, instead of once after loop

  3. Negate the existence of file check, for correct comment

  4. And heed terdon's warning, if you have same named files in your source tree, you will only get one copy in destination.

Try this,

while read -d, -r file
do
   find $sourcefolder -name "${file}" -exec cp '{}' $destfolder \;
   ## Check if the file was copied
   [[ ! -e "$destfolder/$file" ]] && echo "File $file was not copied"
done < "$csv"
echo "Finished"

Update:

This solution works if your CSV is like this

fileA,fileB,fileC,fileD, ...

However since you say terdon's solution works your file must look like this

fileA,valueA1,valueA2,valueA3
fileB,valueB1,valueB2,valueB3
fileC,valueC1,valueC2,valueC3
fileD,valueD1,valueC2,valueD3

and the remainder of line after filename is simply discarded.

added 379 characters in body
Source Link
X Tian
  • 10.7k
  • 3
  • 35
  • 51
  1. Your loop is incorrect, since you do nothing with rest

  2. As terdon suggested, check after each copy, instead of once after loop

  3. Negate the existence of file check, for correct comment

  4. And heed terdon's warning, if you have same named files in your source tree, you will only get one copy in destination.

Try this,

while read -d, -r file
do
   find $sourcefolder -name "${file}" -exec cp '{}' $destfolder \;
   ## Check if the file was copied
   [[ ! -e "$destfolder/$file" ]] && echo "File $file was not copied"
done < "$csv"
echo "Finished"

Update:

This solution works if your CSV is like this

fileA,fileB,fileC,fileD, ...

However since you say terdon's solution works your file must look like this

fileA,valueA1,valueA2,valueA3
fileB,valueB1,valueB2,valueB3
fileC,valueC1,valueC2,valueC3
fileD,valueD1,valueC2,valueD3

and the remainder of line after filename is simply discarded.

  1. Your loop is incorrect, since you do nothing with rest

  2. As terdon suggested, check after each copy, instead of once after loop

  3. Negate the existence of file check, for correct comment

  4. And heed terdon's warning, if you have same named files in your source tree, you will only get one copy in destination.

Try this,

while read -d, -r file
do
   find $sourcefolder -name "${file}" -exec cp '{}' $destfolder \;
   ## Check if the file was copied
   [[ ! -e "$destfolder/$file" ]] && echo "File $file was not copied"
done < "$csv"
echo "Finished"
  1. Your loop is incorrect, since you do nothing with rest

  2. As terdon suggested, check after each copy, instead of once after loop

  3. Negate the existence of file check, for correct comment

  4. And heed terdon's warning, if you have same named files in your source tree, you will only get one copy in destination.

Try this,

while read -d, -r file
do
   find $sourcefolder -name "${file}" -exec cp '{}' $destfolder \;
   ## Check if the file was copied
   [[ ! -e "$destfolder/$file" ]] && echo "File $file was not copied"
done < "$csv"
echo "Finished"

Update:

This solution works if your CSV is like this

fileA,fileB,fileC,fileD, ...

However since you say terdon's solution works your file must look like this

fileA,valueA1,valueA2,valueA3
fileB,valueB1,valueB2,valueB3
fileC,valueC1,valueC2,valueC3
fileD,valueD1,valueC2,valueD3

and the remainder of line after filename is simply discarded.

Source Link
X Tian
  • 10.7k
  • 3
  • 35
  • 51

  1. Your loop is incorrect, since you do nothing with rest

  2. As terdon suggested, check after each copy, instead of once after loop

  3. Negate the existence of file check, for correct comment

  4. And heed terdon's warning, if you have same named files in your source tree, you will only get one copy in destination.

Try this,

while read -d, -r file
do
   find $sourcefolder -name "${file}" -exec cp '{}' $destfolder \;
   ## Check if the file was copied
   [[ ! -e "$destfolder/$file" ]] && echo "File $file was not copied"
done < "$csv"
echo "Finished"