I have a file like this:
ABC1 OBJECT-TYPE ... ... KEY { XYZ1 } ... ... ABC2 OBJECT-TYPE ... ... ABC3 OBJECT-TYPE ... ... KEY { XYZ3 } ... ...
My first search word is KEY (as its occurs less in a file) and second search word is OBJECT-TYPE. OBJECT-TYPE can occur few lines (may be 5 or 10) above the line with KEY. If a KEY is found in a file, I need output that has the key-value and corresponding object-type-value.
Exactly like:
ABC1 KEY1
ABC2 KEY2
Assuming that you want all keys for all objects, and keys are listed below objects, this is how you might do it:
output:
In case you only want the keys of the first object in each tree of objects, where object trees are separated by an empty line you should try this:
output: