How to get multiple lines out of a file by a regex?
How to get numerous lines out of a documents by a regex?
I usually would love to get numerous lines / change numerous lines by a regex. An instance case:
I am attempting to read component of an XML/SGML documents (they are not always well created or in a foreseeable syntax, so a regex would certainly be more secure than a correct parser. On top of that I would love to have the ability to do this additionally whit entirely disorganized files where simply some keywords are recognized.) in a shell script (working on Solaris and also Linux).
<tag1> <tag2>bar</tag2> </tag1> <tag1> <tag2>foo</tag2> </tag1>
From this I would love to read the
<tag1> if it has
foo someplace within it.
A regex like
(<tag1>.*?foo.*?</tag1>) need to offer the appropriate component yet devices like
grep and also
sed just benefit me with solitary lines. Just how can I get
<tag1> <tag2>foo</tag2> </tag1>
in this instance?