I need to remove unnecessary data from multiple output filespart of each file looks like this# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:18697:4431_2:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# 0 hits found# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:26276:5181_1:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end# 1 hits foundFJ712717_(modified) Trypanosoma brucei brucei from mouse 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, complete sequence; and 5.8S ribosomal RNA gene, partial sequence  M03117:99:000000000-ALL7G:1:1101:26276:5181_1:N:0:196   FJ712717_(modified) 1.42e-137   1   271 53  323# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:26276:5181_2:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end# 1 hits foundFJ712717_(modified) Trypanosoma brucei brucei from mouse 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, complete sequence; and 5.8S ribosomal RNA gene, partial sequence  M03117:99:000000000-ALL7G:1:1101:26276:5181_2:N:0:196   FJ712717_(modified) 1.06e-87    1   197 436 236# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:10339:5290_1:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# 0 hits found# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:10339:5290_2:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# 0 hits foundThe first 4 lines represent one output result# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:7647:16266_2:N:0:215# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# 0 hits foundI need to remove all output results with 0 hitsi.e all the 4 lines(shown above)I have noted that with a result of: 1 hits found, there are 2 extra lines added. The 6th line doesnt start with the # symbol.How can I use thegrep -Bcommand to do this? or any other....please helpMy expected output is a file with only 1 hits found result. as below# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:26276:5181_1:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end# 1 hits foundFJ712717_(modified) Trypanosoma brucei brucei from mouse 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, complete sequence; and 5.8S ribosomal RNA gene, partial sequence  M03117:99:000000000-ALL7G:1:1101:26276:5181_1:N:0:196   FJ712717_(modified) 1.42e-137   1   271 53  323# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:26276:5181_2:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end# 1 hits foundFJ712717_(modified) Trypanosoma brucei brucei from mouse 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, complete sequence; and 5.8S ribosomal RNA gene, partial sequence  M03117:99:000000000-ALL7G:1:1101:26276:5181_2:N:0:196   FJ712717_(modified) 1.06e-87    1   197 436 236# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:11481:5777_1:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end# 1 hits foundJN673389_(modified) Trypanosoma congolense isolate TS07210 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, 5.8S ribosomal RNA gene, and internal transcribed spacer 2, complete sequence; and 28S ribosomal RNA gene, partial sequence M03117:99:000000000-ALL7G:1:1101:11481:5777_1:N:0:196   JN673389_(modified) 2.04e-105   1   231 23  253# BLASTN 2.3.0+# Query: M03117:99:000000000-ALL7G:1:1101:11481:5777_2:N:0:196# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end# 1 hits foundTCU22315_(modified) Trypanosoma congolense IL1180 18S, 5.8S, 28S-LS1, srRNA1, complete sequence, and 28S-LS2 ribosomal RNA, partial sequence    M03117:99:000000000-ALL7G:1:1101:11481:5777_2:N:0:196   TCU22315_(modified) 1.40e-75    1   156 1176    1021Thanks in advance.
uniquely remove unwanted lines in multiple files
text processing;scripting;grep
You can use tac to reverse the lines of file and delete 3 lines before matching pattern including line which contains the matching pattern using sed, like this:tac filename | sed '/0 hits/I,+3 d' | tacand if you want to edit the file in-place you can use -i option in sed command like,tac filename | sed -i '/0 hits/I,+3 d' filename | tac