W
W
wolverine7772019-10-25 02:25:27
bash
wolverine777, 2019-10-25 02:25:27

How to write a bash script that executes all the files in a folder?

Hello,
I need to write a script that will run several files in the same folder (at once or one after the other - it doesn't matter). file1.fastq, file2.fastq, file3.fastq and so on using the fastqc module (this is a program in bioinformatics if someone is not in the subject (I myself learned about it the day before yesterday ..))
The script that runs one file works quite well:

#!/bin/bash
#SBASH --time=20:00:00

module load nixpkgs/16.09
module load fastqc/0.11.8

fastqc /home/blabla/files/file1.fastq
-o /home/outfiles

However, there are 50 such files in the /home/blabla/files/ folder - in principle, it would be possible to write a separate line for each file, but this is nonsense)))
Thus, I want to write a cycle, but so far I can only print a list of files:
find -name '*.fastq' | awk '{printf("fastqc \"%s\"\n", $0)}'

Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Zamyatin, 2019-10-25
@corw

As an option:

find /home/blabla/files/ -maxdepth 1 -name '*.fastq' -exec fastqc {} -o /home/outfiles \;

C
chupasaurus, 2019-10-25
@chupasaurus

for file in $(find /home/blabla/files/ -name '*.fastq')
do
  fastqc "$file" -o /home/outfiles
done

C
CityCat4, 2019-10-25
@CityCat4

To eat, the old clumsy method:

cd /blabla
list=`ls -1 *.fastq`

for onelist in $list
 do
   fastqc $onelist -o /home/outfiles
 done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question