Thank you mikrom, your suggested code worked the way I wanted. Amazed by a simple solution like this. I was over thinking of achieving this using "for" loop with NR-- nonsense. But it appears sometimes there is any easy solution if you think creatively. Thanks again and Happy new year.
Thanks for your response. Let me explain the output requirement one more time. My apologies if it was not clear. I am not a programmer.
TEST FILE:
===========
edit policy mars
set src abc
edit policy abc
edit policy yahoo
edit policy bbc
set dst sds
set src ggg
edit policy cnn
edit policy XXX...
By the way, the reason why I am not able to use "grep -B" the file may contain # of "set" commands with other variables before "edit policy" command e.g. the file could look this this :
TEST FILE:
===========
edit policy mars
set src abc
edit policy abc
edit policy yahoo
edit policy bbc
set...
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...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.