title: How to modify value of a variable in awk with gsub and print it out?
body: <p>I try to cut out a numerical value in a specific column in a specific line. To get the column I use:</p>
  
  <pre><code>awk '/REGEX1/{for(i=1;i&lt;=NF;++i)if($i~/REGEX2/)print $i}' $file
  </code></pre>
  
  <p>The output is as desired:</p>
  
  <pre><code>executionTime="120"
  </code></pre>
  
  <p>But I'm just interested in the numerical value. If I use</p>
  
  <pre><code>awk '/REGEX1/{for(i=1;i&lt;=NF;++i)if($i~/REGEX2/)print $i}' $file | awk '{gsub(/[^0-9]/,""); print}')
  </code></pre>
  
  <p>or</p>
  
  <pre><code>awk 'BEGIN{sedcmd="sed 's/[^0-9]//g'"} /REGEX1{for(i=1;i&lt;=NF;++i)if($i~/REGEX2/) print $i | sedcmd}' tmpfile
  </code></pre>
  
  <p>it works. But as soon as I try to use sub(), gsub() or gensub() within an action block it fails. For example with:</p>
  
  <pre><code>awk '/REGEX1/{for(i=1;i&lt;=NF;++i)if($i~/REGEX2/)print gsub(/[^0-9]/,"",$i)$i}' $file
  </code></pre>
  
  <p>the output is 7.</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>gawk -V
  GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.1)
  </code></pre>