TEST FILE:
===========
edit policy mars
set src abc
edit policy abc
edit policy yahoo
edit policy bbc
edit policy cnn
edit policy XXX
set dst abc
edit policy yyy
set src abc
=========================
What I want to do here is find "abc" in the text file (could be 100+ lines) and only display lines if the line starts with "edit policy" with word 'abc' in it e.g. "edit policy abc" and if it finds word "abc" in any other line not starting with "edit policy" e.g. "set src" or "set dst" then perform a reverse lookup from that matching line and print the first line starting with "edit policy".
e.g. the desired output of the search would be like following:
edit policy mars
edit policy abc
edit policy XXX
edit policy yyy
===========
edit policy mars
set src abc
edit policy abc
edit policy yahoo
edit policy bbc
edit policy cnn
edit policy XXX
set dst abc
edit policy yyy
set src abc
=========================
What I want to do here is find "abc" in the text file (could be 100+ lines) and only display lines if the line starts with "edit policy" with word 'abc' in it e.g. "edit policy abc" and if it finds word "abc" in any other line not starting with "edit policy" e.g. "set src" or "set dst" then perform a reverse lookup from that matching line and print the first line starting with "edit policy".
e.g. the desired output of the search would be like following:
edit policy mars
edit policy abc
edit policy XXX
edit policy yyy