I have a lot of files with names in the same format –
four alphanumeric characters, .pdb, and a digit
– and I would like to copy them into corresponding directories.
For example, in the directory home/Desktop/chain/file I have these files:
1b47.pdb1
3rty.pdb1
3rty.pdb3
7yt5.pdb1
7yt5.pdb2
7yt5.pdb5
Now I have created a lot of directories under home/Desktop/chain;
the names of the directories are:
1b47_A
1b47_B
3rty_H
7yt5_2
7yt5_5
7yt5_L
I would like to copy the files in the file directory
into the directories with the same base name.
The result would be this:
1b47_A -> 1b47.pdb1
1b47_B -> 1b47.pdb1
3rty_H -> 3rty.pdb1 3rty.pdb3
7yt5_2 -> 7yt5.pdb1 7yt5.pdb2 7yt5.pdb5
7yt5_5 -> 7yt5.pdb1 7yt5.pdb2 7yt5.pdb5
7yt5_L -> 7yt5.pdb1 7yt5.pdb2 7yt5.pdb5
I’m not very familiar with programming languages but I tried with this code:
cd home/Desktop/chain/file
for name in ????; do cp -r $name.pdb? home/Desktop/chain/????; done
But I got a different and not desired result. Could someone help me please?
I use a script and I don't do this manually because there are many files and directories.