如果下一行包含则打印

如果下一行包含则打印

我有一个文本文件,其中 0 个命中发现需要蛋白质。我使用的是Linux suse。任何使用 awk 或 sed 的命令都将受到赞赏

# BLASTP 2.2.31+
# Query: ABO10498.2 DNA replication initiator protein [Acinetobacter baumannii ATCC 17978]
# Database: uniprot-reviewed%3Ayes+AND+proteome%3Aup000005640.fasta
# Fields: query id, subject id, evalue, % identity, % query coverage per subject
# 1 hits found
# BLASTP 2.2.31+
# Query: ABO10538.2 hypothetical protein A1S_0043 [Acinetobacter baumannii ATCC 17978]
# Database: uniprot-reviewed%3Ayes+AND+proteome%3Aup000005640.fasta
# 0 hits found
# Query: ABO10591.2 putative acetyl-coA synthetase/AMP-(fatty) acid ligase [Acinetobacter baumannii ATCC 17978]
# Database: uniprot-reviewed%3Ayes+AND+proteome%3Aup000005640.fasta
# Fields: query id, subject id, evalue, % identity, % query coverage per subject
# 23 hits found
# BLASTP 2.2.31+
# Query: ABO10598.2 eR transcriptional regulator [Acinetobacter baumannii ATCC 17978]
# Database: uniprot-reviewed%3Ayes+AND+proteome%3Aup000005640.fasta
# 0 hits found

期望的输出:

# BLASTP 2.2.31+
# Query: ABO10538.2 hypothetical protein A1S_0043 [Acinetobacter baumannii ATCC 17978]
# Database: uniprot-reviewed%3Ayes+AND+proteome%3Aup000005640.fasta
# 0 hits found
# BLASTP 2.2.31+
# Query: ABO10598.2 eR transcriptional regulator [Acinetobacter baumannii ATCC 17978]
# Database: uniprot-reviewed%3Ayes+AND+proteome%3Aup000005640.fasta
# 0 hits found

答案1

如果模式保持不变,您可以使用

grep -B 3 '# 0 hits found'

这将打印包含# 0 hits found匹配项之前的三行的所有行。

不同的命中由一条连续的线分散开来--。所以你可能想添加| grep -v '^--'到命令中。

相关内容