title: use one awk command to search for a string within a matching string
body: <p>I want to use awk to search for a string within a matching string. But the awk <a href="http://en.wikibooks.org/wiki/An_Awk_Primer/Search_Patterns_%281%29" rel="nofollow noreferrer">guides</a> and <a href="http://www.unix.com/shell-programming-scripting/158891-awk-multiple-line-search-replace-one-liner.html" rel="nofollow noreferrer">examples</a> I've found only employ one match, or <a href="https://stackoverflow.com/questions/11570253/nested-awk-commands">promising sounding SO questions</a> have answers so <a href="https://stackoverflow.com/questions/10206418/how-to-use-awk-to-search-for-a-complete-match-of-text-within-one-column-of-a-csv">specific</a> that I can't easily draw general principals from them to solve my issue.</p>
  
  <p>For example, I want to get the event handler number for the "Thinkpad Extra Buttons" device from a <code>cat /proc/bus/input/devices</code> command with text like this:</p>
  
  <pre><code>I: Bus=0011 Vendor=0001 Product=0001 Version=ab54
  N: Name="AT Translated Set 2 keyboard"
  H: Handlers=sysrq kbd event3 
  B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
  
  I: Bus=0019 Vendor=17aa Product=5054 Version=4101
  N: Name="ThinkPad Extra Buttons"
  P: Phys=thinkpad_acpi/input0
  H: Handlers=rfkill kbd event7 
  B: KEY=18040000 0 10000000000000 0 101501b00102004 8000000001104000 e000000000000 0
  
  I: Bus=0003 Vendor=04f2 Product=b2ea Version=0518
  N: Name="Integrated Camera"
  P: Phys=usb-0000:00:1a.0-1.6/button
  </code></pre>
  
  <p>To produce output that looks something like</p>
  
  <pre><code>H: Handlers=rfkill kbd event7
  </code></pre>
  
  <p>Using <a href="http://www.chemie.fu-berlin.de/chemnet/use/info/gawk/gawk_9.html#SEC92" rel="nofollow noreferrer">record range patterns</a> I can grab out just the "Thinkpad Extra Buttons" block, but then trying to add another search pattern like this:</p>
  
  <pre><code>cat /proc/bus/input/devices | awk '/Think/,/event/ {print}; /event/ {print $2} 
  </code></pre>
  
  <p>I get all the unrelated Handlers lines, not just the one for "Thinkpad Extra Buttons"</p>
  
  <pre><code>Handlers=event0
  Handlers=kbd
  Handlers=kbd
  Handlers=sysrq
  N: Name="ThinkPad Extra Buttons"
  P: Phys=thinkpad_acpi/input0
  S: Sysfs=/devices/platform/thinkpad_acpi/input/input7
  U: Uniq=
  H: Handlers=rfkill kbd event7 
  Handlers=rfkill
  Handlers=kbd
  Handlers=event9
  Handlers=event10
  </code></pre>
  
  <p>I realize I could pipe the results of that range pattern into a separate awk command and search on the H: Handlers line. However that doesn't work when I want to find multiple Thinkpad named devices, but really it seems like awk should be able to do this kind of thing and it bugs me that I haven't figured it out yet.</p>