How to print three consecutive lines after a pattern, which is in a different file

advertisements

I am beginner, hoping somebody can help me out. I would like to use awk (or sed) to do this task.

I have two files,

File 1

@HWI-M01162:73:000000000-A7TPE:1:1101:17896:1432
@HWI-M01162:73:000000000-A7TPE:1:1101:14465:1433

File 2

@HWI-M01162:73:000000000-A7TPE:1:1101:17896:1432 1:N:0:CTTGTA
CCCCAATGTGATCTGTTTACATTCCAACTCAGCTTCCTCTTGTAAATGTTTTTCTTTTTAC
+
8ABC-6F,C<,CFF9FGGAE9FGFF9<EFF9,CEEEEGGGG9E,,,C<FFFGGGGGGGGGG
@HWI-M01162:73:000000000-A7TPE:1:1101:14465:1433 1:N:0:CTTGTA
CCCATGATGGTACGAAAGTACACATTTTATTTCTTATAAGCAATGGGTTTACTCAGCCTGA
+
@CC<CA9F<<FCFE>[email protected]?FFGG9FFFFGGCF9,<EA8FC8EF[email protected]
@HWI-M01162:73:000000000-A7TPE:1:1101:15447:1444 1:N:0:CTTGTA
CTCTATCTAGAGTTGCCTTCATCAGTTTATCAAAAACACAACCTTAAAAAGGCAACCCCTG
+
[email protected]<@9FF9EEFGF9FF9<FFFEFF99,,<B8C<[email protected],,,,,:C8<FEFEF8
@HWI-M01162:73:000000000-A7TPE:1:1101:15876:1444 1:N:0:CTTGTA
CTCTTTATTTAGTTTTAACTTATCTCAAAAATTACTCGACCTAAAAAATTTGGCCTGTTTA
+
-8CCCG-EFFA9FFFG98FFF9FEEE9,,,,CFAEFF7,@CF,,,,,+CEF9,CFF8EFF,

The out put what I want is as follows. So if the line in file 1 match with line in the file 2, print the line in file 2 together with three consecutive lines. Lines in file 1 are all unique IDs.

@HWI-M01162:73:000000000-A7TPE:1:1101:17896:1432 1:N:0:CTTGTA
CCCCAATGTGATCTGTTTACATTCCAACTCAGCTTCCTCTTGTAAATGTTTTTCTTTTTAC
+
8ABC-6F,C<,CFF9FGGAE9FGFF9<EFF9,CEEEEGGGG9E,,,C<FFFGGGGGGGGGG
@HWI-M01162:73:000000000-A7TPE:1:1101:14465:1433 1:N:0:CTTGTA
CCCATGATGGTACGAAAGTACACATTTTATTTCTTATAAGCAATGGGTTTACTCAGCCTGA
+
@CC<CA9F<<FCFE>[email protected]?FFGG9FFFFGGCF9,<[email protected]


$ awk 'NR==FNR{a[$0];next} $1 in a{c=4} c&&c--' file1 file2
@HWI-M01162:73:000000000-A7TPE:1:1101:17896:1432 1:N:0:CTTGTA
CCCCAATGTGATCTGTTTACATTCCAACTCAGCTTCCTCTTGTAAATGTTTTTCTTTTTAC
+
8ABC-6F,C<,CFF9FGGAE9FGFF9<EFF9,CEEEEGGGG9E,,,C<FFFGGGGGGGGGG
@HWI-M01162:73:000000000-A7TPE:1:1101:14465:1433 1:N:0:CTTGTA
CCCATGATGGTACGAAAGTACACATTTTATTTCTTATAAGCAATGGGTTTACTCAGCCTGA
+
@CC<CA9F<<FCFE>[email protected]?FFGG9FFFFGGCF9,<[email protected]