title: Looping files in bash
body: <p>I want to loop over these kind of files, where the the files with same Sample_ID have to be used together</p>
  
  <pre><code>Sample_51770BL1_R1.fastq.gz
  Sample_51770BL1_R2.fastq.gz
  
  Sample_52412_R1.fastq.gz
  Sample_52412_R2.fastq.gz
  </code></pre>
  
  <p>e.g. Sample_51770BL1_R1.fastq.gz and Sample_51770BL1_R2.fastq.gz are used together in one command to create an output.</p>
  
  <p>Similarly, Sample_52412_R1.fastq.gz and Sample_52412_R2.fastq.gz are used together to create output.</p>
  
  <p>I want to write a for loop in bash to iterate over and create output.</p>
  
  <pre><code>sourcedir=/sourcepath/
  destdir=/destinationpath/
  
  
  bwa-0.7.5a/bwa mem -t 4 human_g1k_v37.fasta Sample_52412_R1.fastq.gz  Sample_52412_R2.fastq.gz&gt;$destdir/Sample_52412_R1_R2.sam
  </code></pre>
  
  <p>How should I pattern match the file names Sample_ID_R1 and Sample_ID_R2 to be used in one command?</p>
  
  <p>Thanks,</p>