sed find pattern on line with another pattern
Posted
by
user2962390
on Stack Overflow
See other posts from Stack Overflow
or by user2962390
Published on 2013-11-06T21:49:00Z
Indexed on
2013/11/06
21:53 UTC
Read the original article
Hit count: 194
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)
© Stack Overflow or respective owner