title: How to separate number and unit from variable when using awk
body: <p>In a 10 line awk script I need to split the content of a variable into a number variable and an unit variable. Here is a simplified example</p>
  
  <pre><code>~$ echo 139506MB | awk '{
     ex = index("KMGTPEZY", substr($1, length($1)));
     val = substr($1, 0, length($1) - 2);
     print ex " " val
     }'
  0 139506
  </code></pre>
  
  <p>I know the unit part is always 2 chars, but for some reason <code>ex</code> always returns <code>0</code> instead of <code>MB</code> as I was hoping.</p>
  
  <p><strong>Question</strong></p>
  
  <p>Any idea why <code>ex</code> doesn't contain the unit?</p>