title: Testing it awk for data with square brackets [syslog]
body: <p>I have a text file like this:</p>
  <pre><code>File1   [test]
  File1   sgfg
  File1   fdgsfg
  File1   [rsyslog]
  File1   moredata
  File1   MAX_EVENTS = 256
  File1   fgsfg
  File1   [other]
  File1   Not this
  File2   [syslog]
  File2   extra
  File2   MAX_EVENTS = 12
  </code></pre>
  <p>With <code>awk</code> I would like to match field $2 when it contains <strong>[syslog]</strong></p>
  <p>Example this works</p>
  <pre><code>awk '$2~/\[syslog\]/' file
  </code></pre>
  <p>But I like to define field in advance using var.</p>
  <p>Not working</p>
  <pre><code>awk -v var=&quot;[syslog]&quot; '$2~var' file
  awk -v var=&quot;\[syslog\]&quot; '$2~var' file
  awk -v var=&quot;syslog&quot; '{test=&quot;[&quot;var&quot;]&quot;} $2~test' file
  </code></pre>
  <p>This works since both sub needs to be true as well as the text match, but complicated :)</p>
  <pre><code>awk -v var=&quot;syslog&quot; 'sub(/^\[/,&quot;&quot;,$2) &amp;&amp; sub(/\]/,&quot;&quot;,$2) &amp;&amp; $2==var' file
  </code></pre>