I have a file with this format name
Pocket_???_????_?.pdb_OUTPUT.txt and some directory with this format ????_?. I need to copy some of this file. For example, I have a list of file and I want to copy only this file in my final directory.
file.txt: Pocket_001_1b47_A.pdb_OUTPUT.txt Pocket_002_1b47_A.pdb_OUTPUT.txt Pocket_001_2cl5_B.pdb_OUTPUT.txt Pocket_001_4rtl_A.pdb_OUTPUT.txt
Each of these files is within its own directory (
4rt1_A) and I would like to enter in each directory and copy them to another destination. The problem is that I do not know how to indicate the directory on the basis of the file name.
I try to use this scripting and this well works but it process all the directory ????_? and since they are many it takes a long time.
for dir in ????_?; do cd $dir/; while read file; do cp $file /home/tommaso/cp_file/; done < /home/tommaso/file.txt ; cd .. ; cd .. ; done
I would like to tell the script to search for files only in direcotry contained in the file name. How can I do that?