I wish to use a for loop for a command that requires two input files. There is a single character change between the two files. Here are two example files:
Fay2_TCCGGAGA-CCTATCCT_L001_R1_001.fastq
Fay2_TCCGGAGA-CCTATCCT_L001_R2_001.fastq
Here is my attempt of the command:
for f in /directory/*R1*.fastq
pref=${basename "$f" _*R1*.fastq}
command input1 $f input2 ${pref}_*R2*.fastq
The issue most likely lies in manipulating the basename so the loop uses the permutation of file1 to find file2. How do I make the basename shorter than the entire file name. I am getting the error
Fay2_TCCGGAGA-CCTATCCT_L001_R2_001.fastq_*R2.fastq does not exist
Thanks to comments below the looping is working properly but my files are being overwritten whenever a the command loops over a new file. The following is my entire command which requires naming both output files.
for f1 in /directory/*R1*.fastq
f2="${f1/_R1_/_R2_}"
pref=${basename "$f" _*R1*.fastq}
command output1 ${pref}_trim_R1.fastq output2 ${pref}_trim_R2.fastq input1 $f input2 $f2