title: How to match until the last occurrence of a character in bash shell
body: <p>I am using <code>curl</code> and <code>cut</code> on a output like below.</p>
  
  <pre><code>var=$(curl https://avc.com/actuator/info | tr '"' '\n' | grep - | head -n1 | cut -d'-' -f -1, -3)
  </code></pre>
  
  <p>Varible <code>var</code> gets have two kinds of values (one at a time).</p>
  
  <pre><code>HIX_MAIN-7ae526629f6939f717165c526dad3b7f0819d85b
  HIX-R1-1-3b5126629f67892110165c524gbc5d5g1808c9b5
  </code></pre>
  
  <p>I am actually trying to get everything until the last '-'. i.e <code>HIX-MAIN</code> or <code>HIX-R1-1</code>.</p>
  
  <p>The command shown works fine to get <code>HIX-R1-1</code>.</p>
  
  <p>But I figured this is the wrong way to do when I have something something like only 1 <code>-</code> in the variable; it is getting me the entire variable value (e.g. <code>HIX_MAIN-7ae526629f6939f717165c526dad3b7f0819d85b</code>).</p>
  
  <p>How do I go about getting everything up to the last '-' into the variable <code>var</code>?</p>