title: How to select only the last match using sed?
body: <p>I want to extract the diagonal numbers of this tensor:</p>
  
  <pre><code> *********** Symmetrised Stress Tensor ***********
   *                                               *
   *          Cartesian components (GPa)           *
   * --------------------------------------------- *
   *             x             y             z     *
   *                                               *
   *  x      3.832865      0.000000      0.000000  *
   *  y      0.000000      3.832865      0.000000  *
   *  z      0.000000      0.000000      3.922869  *
   *                                               *
   *  Pressure:   -3.8629                          *
   *                                               *
   *************************************************
  </code></pre>
  
  <p>For this purpose I tried the following</p>
  
  <pre><code>sed -n 's/.*\* *x *\([0-9.-]*\).*/\1/p' file1 &gt;&gt; x_component.txt
  </code></pre>
  
  <p>However, since there are several of these tensors, this gives me all possible matches in file1. And I only want the last match (only the x-component of the last tensor).</p>
  
  <p>Desired output is:</p>
  
  <pre><code>3.832865 
  </code></pre>
  
  <p>in file x-component.txt</p>
  
  <pre><code>3.832865
  </code></pre>
  
  <p>in file y-component.txt, etc</p>