让我们考虑两个文件,文件 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
使用 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
行尾随上下文。