sed find pattern on line with another pattern
- by user2962390
I am trying to extract text from a file between a '<' and a '', but only on a line starting with another specific pattern.
So in a file that looks like:
XXX Something here
XXX Something more here
XXX <\Lines like this are a problem
ZZZ something <\This is the text I need
XXX Don't need any of this
I would like to print only the "<\This is the text I need".
If I do
sed -n '/^ZZZ/p' FILENAME
it pulls the correct lines I need to look at, but obviously prints the whole line.
sed -n '/</,//p' FILENAME prints way too much.
I have looked into grouping and tried
sed -n '/^ZZZ/{/</,//} FILENAME but this doesn't seem to work at all.
Any suggestions? They will be much appreciated.
(Apologies for formatting, never posted on here before)