Ubuntu: print if next line contains



Question:

I have a text file from which 0 hits found protein is needed. I am using Linux suse. Any command using awk or sed will be appreciated

# 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  

desired output:

# 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  


Solution:1

If the pattern stays the same, you can use

grep -B 3 '# 0 hits found'  

This will print all lines containing # 0 hits found and the three lines before the match.

The different hits are sperated by a line contining --. So you might want to add | grep -v '^--' to the command.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »