Can I use sed
if I need to extract a pattern enclosed by a specific pattern, if it exists in a line?
Suppose I have a file with the following lines :
There are many who dare not kill themselves for [/fear/] of what the neighbors will say.
Advice is what we ask for when we already know the
/*
answer*/
but wish we didn’t.
In both the cases I have to scan the line for the first occurring pattern i.e ' [/
' or '/*
' in their respective cases and store the following pattern till then exit pattern i.e ' /
] 'or ' */
' respectively .
In short , I need fear
and answer
.If possible , Can it be extended for multiple lines ;in the sense ,if the exit pattern occurs in a line different than the same .
Any kind of help in the form of suggestions or algorithms are welcome. Thanks in advance for the replies