I'm trying to delete lines that contain a certain pattern and the line directly above this specific pattern in a file. The pattern is 'Query '. The file looks something like this:
1. Query= ENST00000641267.1
2. Query= ENST00000641448.1
3. Query= MSTRG.3294.1
4. Query= ENST00000435134.2
5. Query= ENST00000503142.1
6. Query= ENST00000503142.1
7. Query 8 THSLRYFRLGVSDPIHGVPEFISVGYVDSHPITTYDSVTQQKEPRAPWMAENLVPDHWER 187
8. Query 188 YTQLLKGWQQMFRVELKRQQRHYNHSGSHTYQRMIGCELLEDGSTTGFLQYAYDGQNFLI 367
9. Query 368 FNKDTLS*LAVDNVAHTIKRAREANQHELQYQKNWLEEECIA*LKRFLEYGKDTQQ 535
10. Query= ENST00000612670.1
11. Query 1 MVFTQAPAEIMGHLRICSLLARQCLAEFLGVFVLMLLTQGAVAQAVTSGETKGNFFTMFL 180
12. Query 181 AGSLAVTIAIYVGGNVSG 234
13. Query= MSTRG.3309.1
So line 6 to 12 should be deleted while all other lines should be preserved. I've tried the following to remove the line before the pattern but can't get it to work:
tac | sed '/Query /'I, +1 d' | tac file.txt > newfile.txt
It just outputs the '>' sign. Can anyone help with this?
Desired output is:
1. Query= ENST00000641267.1
2. Query= ENST00000641448.1
3. Query= MSTRG.3294.1
4. Query= ENST00000435134.2
5. Query= ENST00000503142.1
13. Query= MSTRG.3309.1
Thanks!