(This question is more of data/file management in UNIX/Mac OS X, but the data are fastq files anyway, so I'm asking this question here.)
I have many fastq files scattered in different directories (compressed directories as bz2 or tar.bz2 and non-compressed directories) and I'd like to collect these fastq files in one directory while changing the filenames according to their original directory names. So, my files look a bit like this:
>parentdirectory ->this -->data --->sample1 ---->target.fastq.bz2 ---->anotherfastq.fastq.bz2 ---->anotherfile.bz2 --->sample2 ---->target.fastq.bz2 ---->anotherfastq.fastq.bz2 ---->anotherfile.bz2 ->that -->those --->data.tar.bz2 >anotherdirectory ->data -->sample_a --->target.fastq.bz2 --->anotherfastq.fastq.bz2 --->anotherfile.bz2 -->sample_b --->target.fastq.bz2 --->anotherfastq.fastq.bz2 --->anotherfile.bz2
Please notice that the compressed data.tar.bz2 directory contains the same structure as other non-compressed data directories. My goal is to collect those target.fastq files uncompressed in one directory while changing the filename text "target" into its corresponding parent directory ("sample1", "sample2", "sample_a", etc.).
Any idea how to do that automatically/programmatically?
Thank you in advance for your kind help!