Search code examples
awkpattern-matchingfastq

I'm trying to compare two fastq file(paired reads),print line number n of another file


I'm trying to compare two fastq reads(paired reads) such that position(considering line number) of pattern match in file1.fastq is compared to file2.fastq. I want to print what lies on the same position or line number in file2.fastq. I'm trying to do this through awk. Ex. If my pattern match lies in line number 200 in file1, I want to see what is there in line 200 in file 2. Any suggestion on this appreciated.


Solution

  • In general, you want this form:

    awk '
        { getline line_2 < "file2" }
        /pattern/ { print FNR, line_2 }
    ' file1
    

    Alternately, paste the files together first (assuming your shell is bash)

    paste -d $'\1' file1 file2 | awk -F $'\1' '$1 ~ /pattern/ {print FNR, $2}'
    

    I'm using CtrlA as the field delimiter, assuming that characters does not appear in your files.