Using awk
:
ls -1 *.fastq | awk -F_ '$8 == "R1" {system("cat " $0 ">>" $1 "_R1.out")}'
List all files *.fastq
into awk
, splitting on _
. Check if 8:th part $8
is R1
, then append cat >>
the file into first part $1
+ _R1.out
, which will be comp900_R1.out
or comp995_R1.out
. It is assumed that no filenames contain spaces or other special characters.
Result:
File comp900_R1.out
containing all lines from
comp900_c0_seq1_Glicose_1_ACTTGA_merge_R1_001.fastq
comp900_c0_seq2_Glicose_1_ACTTGA_merge_R1_001.fastq
and file comp995_R1.out
containing all lines from
comp995_c0_seq1_Xilano_1_AGTCAA_merge_R1_001.fastq