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!