title: Awk: Cannot concatenate strings
body: <p>I'm currently dealing with AWK, and I have three variables I work with:</p>
  
  <ul>
  <li>$0 variable - for this example it's equivalent to:</li>
  </ul>
  
  <p><code>path/filename.cpp LOG_ERR &lt;&lt; "error in this log" &lt;&lt; e.what();</code></p>
  
  <ul>
  <li>$logName variable - I parsed out the name of the cpp file, namely:</li>
  </ul>
  
  <p><code>filename</code></p>
  
  <ul>
  <li>$2 variable - contains the default second value:</li>
  </ul>
  
  <p><code>LOG_ERR</code></p>
  
  <p><strong>Question:</strong></p>
  
  <p>What I'm trying to do is concatenate values like so:</p>
  
  <p><code>logName=$logName $2;</code></p>
  
  <p>But instead of the expected value <code>filenameLOG_ERR</code>, I get this:</p>
  
  <p><code>filename LOG_ERR &lt;&lt; "error in this log" &lt;&lt; e.what();</code></p>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT: AWK code as requested:</p>
  
  <pre><code>awk '{
  logName=sub(/^.*\//,"",$1);
  logName=sub(/\..*:/,"",$logName);
  
  print $logName;
  print $2;
  
  logName=$logName $2;
  
  print $logName;
  }' $file
  </code></pre>
  
  <p>EDIT2: Fixed. Never call on any $ variables in awk unless it's a field number. :)</p>
  
  <pre><code>awk '{
  logName=$1;
  sub(/^.*\//,"",logName);
  sub(/\..*:/,"",logName);
  print logName;
  logName=logName $2;
  print logName;
  }' $file
  </code></pre>