1

I am trying to optimize a for loop to download files from a website based in a file with SPECIES names and their corresponding numbers of ACCESSION. I want the loop to work first with the first species and the first accession number of the each file and so on... I tried the basic rule but it is not working.

        #!/bin/sh
        #Load modules
        module load sra-toolkit/2.10.7-centos_linux64

Automatized download and assembly of transcritomes. SRA accession and species code required as arguments for the script


        WORKSPACE=/vto
        WORKSPACEFINAL=/vto
        SPECIES=${WORKSPACE}/species_names.txt
        ACCESSION=$accession_numers.txt

        for i in $SPECIES
            for j in $ACCESION
        do
        mkdir $SPECIES
        cd $SPECIES

#SRA download and processing.

        prefetch $ACCESSION

        fastq-dump --defline-seq '@$sn[_$rn]/$ri' --split-files       ${WORKSPACEFINAL}/ncbi/public/sra/${ACCESSION}.sra -O  ${ACCESSION} 
 

        done
2
  • 2
    why aren't you using $i and $j inside the loop? Commented Jan 28, 2021 at 17:52
  • sorry you are right!!! Commented Jan 29, 2021 at 16:43

1 Answer 1

1

Do you have two loops and just one done and do you have that working?
And as @Mheni said it seems that you aren't using the loop's variables
Here an example of a simple script with two loops one inside the other

file_a=$(cat file_a.txt)
file_b=$(cat file_b.txt)

for i in $file_a
do

        for j in $file_b
        do
                printf "$i\n"
                printf "$j\n"
        done
#// if you add code here is outside j loop

done

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

1 Comment

this worked perfectly, thanks specially for the patience with the new ones in programming!

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.