我是初学者,希望有人可以帮助我。我想用awk(或sed)来完成这个任务。
我有两个文件,
档案1
@HWI-M01162:73:000000000-A7TPE:1:1101:17896:1432
@HWI-M01162:73:000000000-A7TPE:1:1101:14465:1433
文件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>87@FCFAF?FFGG9FFFFGGCF9,<EA8FC8EFFGEFGG98@FFC8
@HWI-M01162:73:000000000-A7TPE:1:1101:15447:1444 1:N:0:CTTGTA
CTCTATCTAGAGTTGCCTTCATCAGTTTATCAAAAACACAACCTTAAAAAGGCAACCCCTG
+
AACC@FFGA<@9FF9EEFGF9FF9<FFFEFF99,,<B8C<8@FFGD,,,,,:C8<FEFEF8
@HWI-M01162:73:000000000-A7TPE:1:1101:15876:1444 1:N:0:CTTGTA
CTCTTTATTTAGTTTTAACTTATCTCAAAAATTACTCGACCTAAAAAATTTGGCCTGTTTA
+
-8CCCG-EFFA9FFFG98FFF9FEEE9,,,,CFAEFF7,@CF,,,,,+CEF9,CFF8EFF,
我想要的输出如下。因此,如果文件1中的行与文件2中的行匹配,则将文件2中的行与三个连续行一起打印。文件1中的行都是唯一ID。
@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>87@FCFAF?FFGG9FFFFGGCF9,<EA8FC8EFFGEFGG98@FFC8
答案 0 :(得分:2)
$ 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>87@FCFAF?FFGG9FFFFGGCF9,<EA8FC8EFFGEFGG98@FFC8
答案 1 :(得分:1)
这个 awk 会这样做:
awk 'FNR==NR{k[FNR]=$0; next}
{data[FNR]=$0; next}
END{
for (i=1;i in k;i++) {
for (j=1; j in data; j++){
if (data[j]~k[i]){
for (x=0; x<4; x++)
print data[j+x]
j+=x
}
}
}
}' f1 f2