I am trying to copy specific files to specific folders, but the file names are like, Long_John_Silver, Miss_Havisham and Master_Pip and the folder names are like Long, Miss and Master. So essentially I'm trying to copy the files to their respective folders e.g. Master_Pip.txt into the folder named Master. And so what I've tried to do is to capture the first word of the file name and somehow use that as a reference, however, it is at this point that I falter.
for fldr in /home/playground/genomes* ; do
find . -name *fna.gz | while read f ; do
f_name=$( echo $fldr | cut -d '/' -f 7 | cut -d '_' -f 1) ;
#echo $f_name ;
if [ "$f_name" == /home/playground/port/"$f_name" ]; then
cp -r "$f" /home/playground/port/"$f_name"/ ;
else
continue
fi
done
done
edit-----------------------------------------------
for fldr in /home/p995824/scripts/playground/genomes_2/* ; do
find . -name *fna.gz | while read f ; do
basenm=${fldr##*/} ; f_name=${basenm%%_*} ;
cp -r $f /home/p995824/scripts/playground/port/$f_name/ ;
done
done
This script copies all the files to all the folders. But I am struggling to construct a condition statement that will specific to which folder each file is copied to. I've tried the if statement as you can see, but I must be constructing it wrongly. Any help is much appreciated.
Aucun commentaire:
Enregistrer un commentaire