title: get line with second last occurrence of words in linux
body: <p>I have two values "usb 1-3" and  "address 20". Now I am trying to search a text file ( basically a log file) which has both of these words.</p>
  
  <p>Now that file has many lines with these words as:</p>
  
  <pre><code>Apr 27 13:30:55 box2 kernel: usb 1-3: USB disconnect, address 20
  and
  Apr 27 13:25:43 box2 kernel: usb 1-3: new high speed USB device using ehci_hcd and address 20
  </code></pre>
  
  <p>Now my requirement is that: I want to get the line with the second-to-last occurrence of these two words and then next 16 lines after that. Like if there are 6 occurrences in file (6 lines with both of these words) then I need the line with the 5th occurrence and the next 16 lines after it. If there are 10 occurrences then I need the 9th occurrence and the next 16 lines.</p>
  
  <p>currently I was using </p>
  
  <pre><code>egrep -A 20 'usb 1-3:.*address 20' filename | tail -16 &gt; output.
  </code></pre>
  
  <p>but it gives me last occurrence. not second-to-last. please note that line should have Both Words and in same order (usb 1-3 first and address 20 later)
  Please tell me if my question isn't clear. Thanks in advance.</p>