wrutter
wrutter

Reputation: 1

applying the same command to multiple files in multiple subdirectories

I have a directory with 94 subdirectories, each containing one or two files *.fastq. I need to apply the same python command to each of these files and produce a new file qc_*.fastq.

I know how to apply a bash script individually to each file, but I'm wondering if there is a way to write a bash script to apply the command to all the files at once

Upvotes: 0

Views: 149

Answers (2)

Ying Xiong
Ying Xiong

Reputation: 4928

You can try find . -name "*.fastq" | xargs your_bash_script.sh, which use find to get all the files and apply your script to each one of them.

Upvotes: 2

nanny
nanny

Reputation: 1108

Use find:

find . -type f -iname "*.fastq" -exec python script {} \;

.: The top-most directory

-type f: Only files

-iname "*.fastq": File name ends in .fastq (case insensitive)

-exec python script: The command you want to execute.

Upvotes: 3

Related Questions