title: How to use variable including special symbol in awk?
body: <p>For my case, if a certain pattern is found as the second field of one line in a file, then I need print the first two fields. And it should be able to handle case with special symbol like backslash.</p>
  
  <p>My solution is first using sed to replace \ with \\, then pass the new variable to awk, then awk will parse \\ as \ then match the field 2.</p>
  
  <pre><code>escaped_str=$( echo "$pattern" | sed 's/\\/\\\\/g')    
  input | awk -v awk_escaped_str="$escaped_str"  '$2==awk_escaped_str { $0=$1 " "     $2 " "}; { print } '
  </code></pre>
  
  <p>While this seems too complicated, and cannot handle various case.</p>
  
  <p>Is there a better way which is more simpler and could cover all other special symbol?</p>