#!/bin/bash
#script to loop through directories to merge fastq files
sourcedir=/path/to/source
destdir=/path/to/dest
for f in $sourcedir/*
do
zcat *R1*.fastq.gz | gzip > $destdir/R1.fastq.gz
zcat *R2*.fastq.gz | gzip > $destdir/R2.fastq.gz
done
Here there are about 30 sub-directories in the directory 'source'. Each sub-directory has certain .fastq.gz files that I want to merge into one .fastq.gz file and save the merged file to the destination directory. As you can see, I am creating files dynamically in my program. I want their names to match the directory name (essentially $f) in which fastq files are present. Is there a way to assign names to the files dynamically?