title: mimicking `grep --only-matching` in awk
body: <p>I've got a <code>bash</code> script that handles a bunch of input and then prints out prettily-formatted output. At the moment it's very modular -- it spawns tons of subshells and uses <code>echo</code>, <code>grep</code>, <code>sort</code>, <code>wc</code>, &amp; <code>sed</code> a lot, but I'm working on replacing the functionality of multiple chunks with larger <code>awk</code> chunks, for better efficiency.</p>
  
  <p>One struggle: I've been trying to figure out how to search input for specific strings, only printing the exact thing I'm searching for. I've been playing with awk's <code>match</code> function but haven't had any success yet. Here's an example of one thing I'm trying to figure out how to integrate into a larger awk script:</p>
  
  <pre><code>$ egrep -o "pae|lm|vmx|svm|ht" /proc/cpuinfo | sort -u
  ht
  lm
  pae
  vmx
  </code></pre>
  
  <p>If I were to use awk to do the same thing, I'd want to end up with an array or variable containing each string I searched for that it found. The main problem as I see it is that each string I'm searching for might exist more than once in the input. Maybe I just need to buy an awk book... Any feedback welcome.</p>