title: Bash/Shell How to remove extra spaces in a variable?
body: <p>How to remove extra spaces in a variable?</p>
  
  <pre><code>VAR="    Eget ac vel volutpat      dic  tumst   est dui      adipiscing  "
  
  Correct result: VAR="Eget ac vel volutpat dic tumst est dui adipiscing" 
  </code></pre>
  
  <p>There are over 16,000,000 to be edited; <code>sed</code> is too slow!</p>
  
  <p>!!! E D I T !!!</p>
  
  <p>String OK! Thank you all</p>
  
  <p>BUT</p>
  
  <p>Text in array problem, gaps remain :-(</p>
  
  <pre><code>ITM=("  Eget ac  vel volutpat   |  Vel volutpat     dic tumst "
       "    Vestibulum  laoreet     a semper  |orttitor      eu laoreet justo congue ")
  
  IFS=$'|'
  
  for (( i=0 ; i&lt;16000000 ; i++ ))
  do
      AAA=( ITM[$i] )
      B=${AAA[0]}     # "  Eget ac  vel volutpat   "
      C=${AAA[1]}     # "  Vel volutpat     dic tumst "
  
  done
  </code></pre>