Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

Bash loop using two input files as lists

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
question from:https://stackoverflow.com/questions/65942404/bash-loop-using-two-input-files-as-lists

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
"
                printf "$j
"
        done
#// if you add code here is outside j loop

done


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...