title: Use Awk to extract substring
body: <p>Given a hostname in format of <code>aaa0.bbb.ccc</code>, I want to extract the first substring before <code>.</code>, that is, <code>aaa0</code> in this case. I use following awk script to do so,</p>
  
  <pre><code>echo aaa0.bbb.ccc | awk '{if (match($0, /\./)) {print substr($0, 0, RSTART - 1)}}'
  </code></pre>
  
  <p>While the script running on one machine <code>A</code> produces <code>aaa0</code>, running on machine <code>B</code> produces only <code>aaa</code>, without <code>0</code> in the end. Both machine runs <code>Ubuntu/Linaro</code>, but <code>A</code> runs newer version of awk(gawk with version 3.1.8 while <code>B</code> with older awk (mawk with version 1.2)</p>
  
  <p>I am asking in general, how to write a compatible awk script that performs the same functionality ...</p>