This question already has an answer here:
- How to perform a multi line grep 8 answers
I would like to know the code for
grep to check for two matches one after the other.
For example I have the following text from one of the search files:
@<TRIPOS>MOLECULE ← pattern 1532 ← ID 17 17 SMALL NO_CHARGES
I need to find the exact match of the ID which is always located one line below pattern and then retrieve the file name from which ID was located.
I used the following command:
grep -Pzo '@<TRIPOS>MOLECULE'(?:.*\n)*?\K1532' filename
but I got files containing 1532 as well as for 153284. I need code for exact ID match.