I have a lot of files that are scattered over 300 directories in a systematic manner:
GA001/curve_1/pdbs/FILES
GA002/curve_1/pdbs/FILES
....
GA300/curve_1/pdbs/FILES
now i need to move all the FILES into the same folder called allPDB. Instead of doing it manually i tried to write a bash-script, but i am clearly quite incompetent. I tried to create a loop which goes from 1 to 300 which update the path where the files are located, but it is not working. my code is shown below
#!/bin/bash
# loop running over the 300 dirs
for i in $(seq 1 300); do
if $i<10; then
printf -v mypath 'GA00%s/curve_1/pdbs' $i
elif $i=>10 && $i<100; then
mypath=$(printf 'GA0%s/curve_1/pdbs' $i)
else
mypath=$(printf 'GA%d/curve_1/pdbs' $i)
fi
echo $mypath # used to check the generated path
cp -pr $mypath/*.pdb allPDB/
done
i have tried using to different implementations of PRINTF according to this thread SPRINTF in shell scripting?. I also tried using both %i, %s and %d in the PRINTF call but the path that is generated for i=9 is "GA9" and not "GA009". Furthermore, i am given the error messages:
MovePDB.sh: line 5: 1: command not found
MovePDB.sh: line 7: 1=: command not found
GA1/curve_1/pdbs
cp: GA1/curve_1/pdbs/*.pdb: No such file or directory
MovePDB.sh: line 5: 2: command not found
MovePDB.sh: line 7: 2=: command not found
GA2/curve_1/pdbs
...
cp: GA98/curve_1/pdbs/*.pdb: No such file or directory
MovePDB.sh: line 5: 99: command not found
MovePDB.sh: line 7: 99=: command not found
GA99/curve_1/pdbs
cp: GA99/curve_1/pdbs/*.pdb: No such file or directory
MovePDB.sh: line 5: 100: command not found
MovePDB.sh: line 7: 100=: command not found
GA100/curve_1/pdbs
MovePDB.sh: line 5: 101: command not found
MovePDB.sh: line 7: 101=: command not found
GA101/curve_1/pdbs
MovePDB.sh: line 5: 102: command not found
MovePDB.sh: line 7: 102=: command not found
Can anyone help me out? I don't understand the "NUMBER(=) command not found" error
Cheers!