I have a folder which has a bunch of files in them, and I'd like to cat together specific files. The layout is like this:
sample1_S99_L1_R1_001.fastq.gz
sample1_S99_L2_R1_001.fastq.gz
sample1_S99_L1_R2_001.fastq.gz
sample1_S99_L2_R2_001.fastq.gz
and so on for different samples. I would like to cat sample1_S99_*_R1_001.fastq.gz into 1 gunzip files. Manually I would do something like this:
cat sample1_S99_L1_R1_001.fastq.gz sample1_S99_L2_R1_001.fastq.gz > sample1.R1.fastq.gz
and
cat sample1_S99_L1_R2_001.fastq.gz sample1_S99_L2_R2_001.fastq.gz > sample1.R2.fastq.gz
My idea was to sort of automate this procedure and I came up with this:
ls | awk -F '[_.]' '{print $1}' > test.txt
sort -u test.txt > names_final.txt
while read line;do cat $line_*_*_R1_*.fastq.gz > $line.R1.fastq.gz
while read line;do cat $line_*_*_R2_*.fastq.gz > $line.R2.fastq.gz
The problem I'm facing now is that these commands seems to cat all R1 files together. If i type for example
ls sample1_*_*_R1_*.fastq.gz
I only get the files I want to cat together. So I'm not sure were my mistake is here.
Anybody has an idea?
Thanks in advance.
