title: BASH: Convert hex representation inside a string to binary equivalent
body: <p>I  want to check inside a binary file if it matches a binary pattern.</p>
  
  <p>For that, I'm using clamAV signature database</p>
  
  <pre><code>Exploit.HTML.ObjectType:3:*:3c6f626a65637420747970653d222f2f2f2f2f2f2f2f2f2f2f2f
  </code></pre>
  
  <p>I code this to retrieve the hex signature string</p>
  
  <pre><code>signature=$(echo "$line" |awk -F':' '{ print $4 }')
  </code></pre>
  
  <p>Moreover I would like to change hex string to binary</p>
  
  <pre><code>tmp=$(echo -n $signature | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs print)
  </code></pre>
  
  <p>Finally I would like to check if my file ( *$raw_file_path* ) matches my binary pattern (now in <em>$tmp</em>)</p>
  
  <pre><code>test_var=$(cat $raw_file_path | grep -U -P "$tmp")
  </code></pre>
  
  <p>I don't why it doesn't work.</p>
  
  <p>If you have any idea.</p>
  
  <p>Thanks.</p>