1

I have a folder with 18 pairs of files with the same name except one has an R1 and the other an R2 , e.g. SM000907_S1_R1.fastq and SM000907_S1_R2.fastq. I would like to throw a command in a loop for all these pairs.

I've tried the following loop, but it's not working (it throws the error "wrong substitution"):

for sample in ${seq 1 18}; do
    merge-paired-reads.sh SM000907_S$sample_R1.fastq SM000907_S$sample_R2.fastq > output
done
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

3

You can use either $(seq 1 18) or {1..18}, but not both at the same time.

Also, your command line does not work because you are using different variable names inadvertently. Surround them with braces.

Finally, as a good practice, quote all the strings that contain a variable:

for sample in {1..18}; do
    merge-paired-reads.sh "SM000907_S${sample}_R1.fastq" "SM000907_S${sample}_R2.fastq" > output
done
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Poshi
  • 5,332
  • 3
  • 15
  • 32