Home > Net >  Creating multiple copies of a file while changing a specific number everytime
Creating multiple copies of a file while changing a specific number everytime

Time:06-24

I have a specific script that I need to duplicate x amount of times (100 times) but I need a specific number in the file to change (increase by one) each time the file is duplicated.

Example:

vina=/home/x/xxx/bin/vina
path=/home/x/xxx/Virtual_Screening

# Execute the job code

for f in $path/*.pdbqt;do
    $vina --config $path/BatchConfig.txt --receptor $path/5u1w_receptor.pdbqt --batch $path/ligands/*.pdbqt --dir $path/outputs/001
done

I would want the script to be changed to:

vina=/home/x/xxx/bin/vina
path=/home/x/xxx/Virtual_Screening

# Execute the job code

for f in $path/*.pdbqt;do
    $vina --config $path/BatchConfig.txt --receptor $path/5u1w_receptor.pdbqt --batch $path/ligands/*.pdbqt --dir $path/outputs/002
done

For more context, I need the script to be duplicated 100 times instead of accessing the 100 folders using * due to disk space limitations.

The particular section of the script that needs editing is the three digit number after '--dir' which needs to increase by 1 each time the file script is copied 001 --> 002 ... --> 010 ... --> 100

I'm quite knew to shell scripting and python scripting so any help would be highly appreciated.

CodePudding user response:

Is that better ? :

for i in $(seq -f "g" 1 100);do
    for f in $path/*.pdbqt;do
        $vina --config $path/BatchConfig.txt --receptor $path/5u1w_receptor.pdbqt --batch $path/ligands/*.pdbqt --dir $path/outputs/$i
    done
done

CodePudding user response:

If by duplicating you mean copying to a new file and changing 001

while read -r i; 
do 
    cp script.sh "script_$i.sh" && sed -i "s/001$/$i/" "script_$i.sh"
done < <(printf '%s\n' {001..100})

$ grep -o "outputs/..." *
script_001.sh:outputs/001
script_002.sh:outputs/002
script_003.sh:outputs/003
script_004.sh:outputs/004
...
  • Related