http://www.perlmonks.org?node_id=1057452


in reply to Print a previous to previous of a matching line

Try this it works for me.

#!/usr/bin/perl -w use strict; use warnings; #open(FILE, "twentySeq1e-10.out") or die("Cannot open file"); my $gi; while(<DATA>){ if(/^# Query: gi.([0-9]+)/) {$gi = $1;} if(/^# 0 hits found/){print "$gi\n";} } __DATA__ # BLASTP 2.2.28+ # Query: gi|338220664|gb|EGP06123.1| hypothetical protein GEW_00005 [P +asteurella multocida subsp. gallicida str. Anand1_poultry] # Database: nr-25sep # Fields: query id, subject id, % identity, alignment length, mismatch +es, gap opens, q. start, q. end, s. start, s. end, evalue, bit score # 2 hits found gi|338220664|gb|EGP06123.1| gi|45383702|ref|NP_989542.1| 45.15 + 206 96 7 3 204 28 220 1e-51 170 gi|338220664|gb|EGP06123.1| gi|15419940|gb|AAK97214.1| 44.17 +206 98 7 3 204 28 220 5e-50 166 # BLASTP 2.2.28+ # Query: gi|338220666|gb|EGP06125.1| hypothetical protein GEW_00015 [P +asteurella multocida subsp. gallicida str. Anand1_poultry] # Database: nr-25sep # 0 hits found # BLASTP 2.2.28+ # Query: gi|338220651|gb|EGP06111.1| hypothetical protein GEW_00275 [P +asteurella multocida subsp. gallicida str. Anand1_poultry] # Database: nr-25sep # 0 hits found

RESULT

Process started >>> 338220666 338220651 <<< Process finished. (Exit code 0)