Home > other >  Bash for loop containing python script
Bash for loop containing python script

Time:02-10

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 pythonscript.py -i fastqfile1.fq -q > stats1.txt

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

for f in *.fq; do python pythonscript.py -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 " looping_script.sh: line 5: syntax error near unexpected token do' looping_script.sh: line 5: do' "

CodePudding user response:

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

for f in *.fq; do 
   python pythonscript.py -i "$f" -q
done > results.txt
  • Related