Dear all,

I would like to write shell script to automatic alignment my pair end data with bowtie (or bwa) aligners.

Problem is, when I have lot of pair-end fastq files in one directory I have problem to loading data in for cycle.

Here is my code:

    for i in $(ls *.fastq | rev | cut -c 22- | rev | uniq)
        do ./bowtie2 --very-sensitive -p32 --rg-id ${i} --rg-sample ${i} --rg-library Illumina --rg-platform Illuimna -x $reference -1 ${i}_L001_R1_001.fatsq.gz -2 ${i}_L001_R2_001.fatsq.gz -S ${i%.fastq.gz}${i}.sam
        done;

This is very nice solution help solved by RamRS. Is there any other way how to treat Bowtie or BWA with many samples (corresponding one sample to each read) in one for cycle?

my directory contains lot of fastq.gz:

    name1_R1_001.fatsq.gz
    name2_R2_001.fatsq.gz
    ...
    ...
    ...

Each sample name (prefix before `R._001.fastq.gz`) has different name length so algorithm above doesn't work properly :-(

Thank you for any idea and solutions..
```
for I in `ls *.fastq | cut -d "_" -f 1` ;
    do ./bowtie2 --very-sensitive -p 32 --rg-id $i --rg-sample $i --rg-library Illumina --rg-platform Illuimna -x $reference -1 $i\_L001_R1_001.fastq.gz -2 $i_L001_R2_001.fastq.gz -S $i.sam ;
done ;
```

edit: removed useless grep