0

I would like to iterate over several files in my directory in linux which look like this:

SRR057629_1.fastq.gz SRR057629_2.fastq.gz SRR057630_1.fastq.gz     
SRR057630_2.fastq.gz SRR057631_1.fastq.gz SRR057631_2.fastq.gz
SRR057632_1.fastq.gz SRR057632_2.fastq.gz SRR057633_1.fastq.gz
SRR057633_2.fastq.gz

The challenge for me is that I would need SRR..._1 and SRR..._2 as input for one command (tophat2) and thereafter take the next couple of SRR***_1 and SRR***_2 for the same command. In principle it would look like this:

tophat2 -G /Homo_sapiens/UCSC/hg19/Annotation/Genes/genes.gtf /Homo_sapiens /UCSC/hg19/Sequence/Bowtie2Index/genome SRR057636_1.fastq.gz SRR057636_2.fastq.gz
tophat2 -G /Homo_sapiens/UCSC/hg19/Annotation/Genes/genes.gtf /Homo_sapiens/UCSC/hg19/Sequence/Bowtie2Index/genome SRR057637_1.fastq.gz SRR057637_2.fastq.gz

So how could I change these numbers (bold) for each command??

SRR0576**29**_1.fastq.gz

SRR0576**29**_1.fastq.gz

Best wishes, Simon

n.y
  • 3,343
  • 3
  • 35
  • 54
S.Baum
  • 117
  • 7

1 Answers1

1
for a in *_1.fastq.gz; do
   tophat2 -G /Homo_sapiens/UCSC/hg19/Annotation/Genes/genes.gtf /Homo_sapiens /UCSC/hg19/Sequence/Bowtie2Index/genome $a ${a/_1/_2}
done
Ipor Sircer
  • 3,069
  • 3
  • 10
  • 15