FASTQ file reads extraction paired ends I have paired end reads and want to extract only those which have this sequence within them:
TGTATGTAAACTTCCGACTTCAACTGTA

I tried using grep -B1 -A2 &quot;TGTATGTAAACTTCCGACTTCAACTGTA&quot; file_1.fq | grep -v &quot;^--$&quot;
and the same from the mate pair. After this I tried aligning them , but they dont align because the reads headers are different.
Can someone help in extracting the mate pair of one read from the other file (2.fq), so that they can be aligned ?
regards.
Your question can be rewritten as, &quot;how do I get the union of reads in two files?&quot; Since you have already subset the mates, the steps are:

Process each file, storing the list of reads names in each.
Take the union of these.
Iterate through the original/non-subset files and write only the reads with names in the union to the output.

The files will be both subset correctly and synced properly such that bowtie2 or any other aligner can correctly process them.