Skip to content

Bash for loop containing python script

New here!

I’m trying to loop a python script in bash that gets stats from fastq files. I want it to loop through all the fastq files in a directory and save the outputs in a text file. Ideally don’t want to edit the python script

This is the script that works when I’m not looping it:

python -i fastqfile1.fq -q > stats1.txt

This is the loop that doesn’t work for me:

for f in *.fq; do python -i "$f" -q;
do echo "${f%.*}" > "stats${f%.fq}.txt" done

Thank you

EDIT I have put the loop in a bash .sh script. The error message I get is ” line 5: syntax error near unexpected token do' line 5: do’ “



Like this if you want all results in a single file:

for f in *.fq; do 
   python -i "$f" -q
done > results.txt
3 People found this is helpful