1

I need to loop through multiple subdirectories to find fastq files.

fastq files are in /path/sample/a/b/c/.fastq

currently I use this:

${inputDir}/**/**/**/*.fastq 

My inputdir will be only: /path/sample, since its three sub folders i use "/**/" three times. But sometimes no of subfolders might change.

Is there any other efficient way to loop through multiple subdirectories.

My bash script:

#! /bin/bash -l

CWD=$(pwd)
dateStamp=$(date +%s)
SeqProj="${inputDir}/**/**/**/*.fastq"

for Dir in $SeqProj
do

done

closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, countermode, Rui F Ribeiro, Anthon Jul 3 '17 at 13:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Once you find these two directories, what do you want to do with them? Right now you are just overwriting those readpair variables then exiting. CWD and datestamp are also unused. – Jeff Schaller Jul 3 '17 at 2:31
2
find / -iname '*.fastq' -exec /path/to/foo.sh {} \;

Then foo.sh is a script that does whatever you are calling inside your loop, using $1 to reference the file found that had its name passed to the script.

Mike's answer also works, it just really depends on what you want to do with it...

0

The easiest way is to use find:

for Dir in $(find "$inputDir" -name '*.fastq')

Not the answer you're looking for? Browse other questions tagged or ask your own question.