title: How to print only matches with sed?
body: <p>Okay, this is an easy one, but I can't figure it out.</p>
  
  <p>Basically I want to extract all links (<code>&lt;a href="[^&lt;&gt;]*"&gt;[^&lt;&gt;]*&lt;/a&gt;</code>) from a big <code>html</code> file.</p>
  
  <p>I tried to do this with <code>sed</code>, but I get all kinds of results, just not what I want. I know that my regexp is correct, because I can replace all the links in a file:</p>
  
  <pre><code>sed 's_&lt;a href="[^&lt;&gt;]*"&gt;[^&lt;&gt;]*&lt;/a&gt;_TEST_g'
  </code></pre>
  
  <p>If I run that on something like</p>
  
  <pre><code>&lt;div&gt;&lt;a href="http://wwww.google.com"&gt;A google link&lt;/a&gt;&lt;/div&gt;
  &lt;div&gt;&lt;a href="http://wwww.google.com"&gt;A google link&lt;/a&gt;&lt;/div&gt;
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>&lt;div&gt;TEST&lt;/div&gt;
  &lt;div&gt;TEST&lt;/div&gt;
  </code></pre>
  
  <p>How can I get rid of everything else and just print the matches instead? My preferred end result would be:</p>
  
  <pre><code>&lt;a href="http://wwww.google.com"&gt;A google link&lt;/a&gt;
  &lt;a href="http://wwww.google.com"&gt;A google link&lt;/a&gt;
  </code></pre>
  
  <p>PS. I know that my regexp is not the most flexible one, but it's enough for my intentions.</p>