I have a very basic question, but I can't get a solution. I have multiple files in the same directory and I would like to concatenate each pair of files. The names are:
Sample1_R1_L001.fastq Sample1_R2_L001.fastq Sample2_R1_L001.fastq Sample2_R2_L001.fastq Sample3_R1_L001.fastq Sample3_R2_L001.fastq
(etc...)
The result I want is to concatenate by sample, such as cat Sample1_R1_L001.fastq Sample1_R2_L001.fastq > Sample1_concat.fastq
I tried this loop, find . -name "_R?_"|while read file; do "$file"R1*.fastq "$file"_R2_L001.fastq > "$file"_merged.fastq
but it didn't work. Any thoughts?
Here's how I'd do it:
Loop over the numbers then build the command... getting the actual filenames is surely possible, but with shell, I just do the simplest thing that can possibly work, even if that means partially brute forcing the loop.
Replace the 1..4 to whatever the limits are and the shell will expand that into all the various numbers for you.