How To Extract Text Between HTML Tags With Or Condition Multiple Times
<p>I have been researching how to extract title tags from html. I've pretty much figured out that regex and html don't mix and that grep can be used. However, the code I found <a href="https://stackoverflow.com/questions/3833088/extract-title-of-a-html-file-using-grep">here</a>, looks like this:</p>

<pre><code>awk -vRS="&lt;/title&gt;" '/&lt;title&gt;/{gsub(/.*&lt;title&gt;|\n+/,"");print;exit}'
</code></pre>

<p>Now, this works to find the text between title tags only once. I would like to know how I can make it run on every line. I could do a <code>cat file; while read line; do ...; done</code>. However, I know that is probably not very efficient an there's a better way.</p>

<p>Secondly, in the file I need to keep any lines that start with string '--'. I believe this requires adding an 'or' statement in <code>awk</code> so that it will match the title tags and any line starting with '--'</p>

<p>The input file would look like this:</p>

<pre><code>text text text &lt;title&gt;random text of the title 1&lt;/title&gt; random html stuff
--time--
xyz more random text &lt;title&gt;random text of the title 2&lt;/title&gt; hmtl text
--time--
some text &lt;title&gt;random text of the title 3&lt;/title&gt; more text tags
--time--
text here &lt;title&gt;random text of the title 4&lt;/title&gt; random text html
--time--
</code></pre>

<p>The desired output:</p>

<pre><code>&lt;title&gt;random text of the title 1&lt;/title&gt;
--time--
&lt;title&gt;random text of the title 2&lt;/title&gt;
--time--
&lt;title&gt;random text of the title 3&lt;/title&gt;
--time--
&lt;title&gt;random text of the title 4&lt;/title&gt;
--time--
</code></pre>

<p>I'm not that great with awk, but I'm learning. I know there should be an option to print all, but it's the OR statement that I'm really stuck on. I am open to sed or grep if you think that's more efficient. Any help or direction is greatly appreciated. </p>