2

I have several files called as follow:

dosulepin3D_CID_5284550.pdbqt
protriptyline3D_CID_4976.pdbqt

These are small molecules. Now I want to create a file in the Results folder for each one of these molecules, ignoring the 3D_CID_5284550.pdbqt they all have behind, and have folders called:

dosulepin
protriptyline

I want to do this with a for loop, since I'm also performing some functions with these files. This is what I have:

DIR="/home/roy/MolecularDocking/VirtualScreening/Dockings"
cd $DIR
for ligand in ligands/*; do
    echo $ligand
    mkdir "/home/roy/MolecularDocking/Results/$ligand"
done;

But this obviuosly creates folders with the full name.

1 Answer 1

4

Something like this.

DIR="/home/roy/MolecularDocking/VirtualScreening/Dockings"
cd "$DIR" || exit

for ligand in ligands/*.pdbqt; do
    echo "$ligand"
    echo mkdir -p "/home/roy/MolecularDocking/Results/${ligand%3D*}"
done

Remove the echo from the mkdir if you're satisfied with the output.

See Parameter Expansion for more details.

Sign up to request clarification or add additional context in comments.

2 Comments

Thankx @Jetchisel. This gives me /home/roy/MolecularDocking/Results/ligands/viloxazine. Is there a way of just getting /home/roy/MolecularDocking/Results/viloxazine
You'll need to do another Parameter Expansion. ligands=${ligand%3D*}; ligand=${ligand/ligands} maybe. The ; can be a new line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.