title: How to remove last part of a string with different length in bash
body: <p>I am trying to collect the lines from a file which doesn't start with a # as its first caracter.
  I have this code I am able to get them:</p>
  <pre><code>while IFS= read -r line
  do
      [[ -z &quot;$line&quot; ]] &amp;&amp; continue
      [[ &quot;$line&quot; =~ ^# ]] &amp;&amp; continue
       #echo &quot;LINEREADED: $line&quot;
  done &lt; $file
  </code></pre>
  <p>So the output I have is something like this:</p>
  <pre><code>modules/core_as/xxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxx [100]
  </code></pre>
  <p>My question is how can I get only the string without the [100]?</p>
  <p>I know there is some commands like sed or trim but the problem is that the string is not always that length, sometimes is different like:</p>
  <pre><code>cross_modules/core_as/xxxx/xxxxxxxxx [100-103]
  </code></pre>
  <p>or</p>
  <pre><code>cross_modules/core_as/xxxxxxxxxxxx/xxxxxxxxx [100-103]
  </code></pre>
  <p>or anything like  that...</p>
  <p>And in all this cases I only need the string without the [....] and without the last blank space at the end of last x, whichever the length of the string is, like cross_modules/core_as/xxxxxxxxxxxx/xxxxxxxxx</p>
  <pre><code>echo ${caseReaded:1:${#caseReaded}-7} 
  </code></pre>
  <p>This also do the job but is not generic for any length.</p>
  <p>Does anyone knows how I can get this?</p>