title: Extract numbers from a string using sed and regular expressions
body: <p>Another question for the sed experts.</p>
  
  <p>I have a string representing an pathname that will have two numbers in it. An example is:</p>
  
  <pre><code>./pentaray_run2/Trace_220560.dat
  </code></pre>
  
  <p>I need to extract the second of these numbers - ie 220560</p>
  
  <p>I have (with some help from the forums) been able to extract all the numbers together (ie 2220560) with:</p>
  
  <pre><code>sed "s/[^0-9]//g"
  </code></pre>
  
  <p>or extract only the first number with:</p>
  
  <pre><code>sed -r 's|^([^.]+).*$|\1|; s|^[^0-9]*([0-9]+).*$|\1|'
  </code></pre>
  
  <p>But what I'm after is the second number!! Any help much appreciated.</p>
  
  <p>PS the number I'm after is always the second number in the string.</p>