让我们考虑两个文件,文件1包含三个单词,文件2包含一些行。我想要的输出应该包含文件2中的行,文件1中有单词,接下来的2行
文件1
EF-hand_motif
Ferritin
Manganese_catalase
文件2
a_1.out:The conserved site of Ferritin is found as: ['EFKEAFSL', 'EAELQDMI', 'EMIREADI']
a_1.out:Length of conserved site: 32
a_1.out:Position: 0-31
g_1.out:The conserved site of EF-hand_motif is found as: ['DADGNGTIDFPE', 'DKDGNGYISAAE']
g_1.out:Length of conserved site: 28
g_1.out:Position: 0-27
d_1.out:The conserved site of Hemerythrin is found as: ['ELRH']
d_1.out:Length of conserved site: 4
d_1.out:Position: 100-103
想要的输出格式
a_1.out:The conserved site of Ferritin is found as: ['EFKEAFSL', 'EAELQDMI', 'EMIREADI']
a_1.out:Length of conserved site: 32
a_1.out:Position: 0-31
g_1.out:The conserved site of EF-hand_motif is found as: ['DADGNGTIDFPE', 'DKDGNGYISAAE']
g_1.out:Length of conserved site: 28
g_1.out:Position: 0-27
答案 0 :(得分:2)
使用grep:
$ grep -Ff file1 -A 2 file2
a_1.out:The conserved site of Ferritin is found as: ['EFKEAFSL', 'EAELQDMI', 'EMIREADI']
a_1.out:Length of conserved site: 32
a_1.out:Position: 0-31
g_1.out:The conserved site of EF-hand_motif is found as: ['DADGNGTIDFPE', 'DKDGNGYISAAE']
g_1.out:Length of conserved site: 28
g_1.out:Position: 0-27
-F
表示匹配固定字符串而不是正则表达式,-f file
表示要与file
匹配的读取模式,-A n
表示在匹配行之后打印尾随上下文的n
行。