awk - print when condition is met

I have a file.txt containing the following:

Query= HWI-ST863:386:C5Y8UACXX:3:2302:16454:89688 1:N:0:ACACGAAT
  
 Length=100
                                                                       Score     E
 Sequences producing significant alignments:                          (Bits)  Value
  
   database                                                            176     3e-45
  
  
 > database
 Length=4312079
  
  Score = 176 bits (194),  Expect = 3e-45
  Identities = 99/100 (99%), Gaps = 0/100 (0%)
  Strand=Plus/Plus
  
 Query  1       CACGCCCTTTGCTTGGCCCTTGGGGATGTGGCAGCTGATTATCCCGATAGGCGACCAGGA  60
                |||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||
 Sbjct  778226  CACGCCCTTTGCTTGGCCCTTGGGGATGTGGCAGCTGATTATCCCGGTAGGCGACCAGGA  778285
  
 Query  61      GTCTCGCAAGCTCCTGCCTTTGCCCCTCAGTCCATTGGAG  100
                ||||||||||||||||||||||||||||||||||||||||
 Sbjct  778286  GTCTCGCAAGCTCCTGCCTTTGCCCCTCAGTCCATTGGAG  778325
 
  
  Score = 26.5 bits (28),  Expect = 3.5
  Identities = 14/14 (100%), Gaps = 0/14 (0%)
  Strand=Plus/Minus
  
 Query  22       GGGGATGTGGCAGC  35
                 ||||||||||||||
 Sbjct  1898269  GGGGATGTGGCAGC  1898256

now I want to use awk to print the following lines (please see the condition below)

Query= HWI-ST863:386:C5Y8UACXX:3:2302:16454:89688 1:N:0:ACACGAAT
Sbjct  778226  CACGCCCTTTGCTTGGCCCTTGGGGATGTGGCAGCTGATTATCCCGGTAGGCGACCAGGA  778285

but only, if this line

 Identities = 99/100 (99%), Gaps = 0/100 (0%)

meets the condition, that Identities should be >50 (so I am only interesting in the part Identities = 99 )

This is my command for printing the second line (it is always the 5th line below the line with Identities):

awk 'c&&!--c;/Identities =/ && ($3+0)>=50 {print q, c=5}' file.txt

the first line in the example output should only be printed, if the condition is met.

I am also able to print the first line only, without a condition:

awk '/Query= / {print $0} file.txt

but now my idea is to combine these to commands, so that the first line and the second line is only printed if the condition is met. I thought of putting the first line into a variable inside awk, and if the condition is met, print this first line and the second line.
I could come up with this:

awk '/Query= /{q=$0}' file.txt | awk 'c&&!--c;/Identities =/ && ($3+0)>=50 {print q, c=5}' file.txt

but it does not work as planned.
Any help is appreciated!

Defining a variable ( q ) in one awk script and using that variable in a different awk script can't work. But, you can easily combine your code into a single awk script:

awk '/Query= /{q=$0} c&&!--c;/Identities =/ && ($3+0)>=50 {print q, c=5}' file.txt

and get what I think you want:

Query= HWI-ST863:386:C5Y8UACXX:3:2302:16454:89688 1:N:0:ACACGAAT 5
 Sbjct  778226  CACGCCCTTTGCTTGGCCCTTGGGGATGTGGCAGCTGATTATCCCGGTAGGCGACCAGGA  778285

You might also consider trying:

awk '
$1 == "Query=" {
	q = $0
	next
}
$1 == "Identities" && ($3 + 0) > 50 {
	print q
	printSbjct = 1
	next
}
printSbjct && $1 == "Sbjct" {
	print
	printSbjct = 0
	next
}' file.txt

which also produces the same output. It is a little be longer, but I find it easier to read and understand.

P.S. Note that your specification said > 50 , but your code used >=50 . I copied the >= when I combined your code, but I used what you specified in your description in the code I wrote.

thank you! that's what I was looking for. and it should have been >=50