title: Awk processing of filenames containing backslash madness
body: <p>I spent a whole day trying to process some files with backslashes and spaces inside their names. No matter what I do awk (gawk) refuses to print backslashes:</p>
  
  <pre><code>echo "this/pathname/contains/spa ces/and/back\\slashes" | xargs -d'\n' -n1 -I{} bash -c 'echo "{}"; echo whatever | gawk "{printf {}}"'
  this/pathname/contains/spa ces/and/back\slashes
  gawk: {printf this/pathname/contains/spa ces/and/back\slashes}
  gawk:                                           ^ syntax error
  gawk: {printf this/pathname/contains/spa ces/and/back\slashes}
  gawk:                                                ^ backslash not last character on line
  </code></pre>
  
  <p>This didn't work since the backspace gets directly into awk code.</p>
  
  <pre><code>echo "this/pathname/contains/spa ces/and/back\\slashes" | xargs -d'\n' -n1 -I{} bash -c 'echo "{}"; echo whatever | gawk "{printf \"{}\"}"'
  this/pathname/contains/spa ces/and/back\slashes
  gawk: warning: escape sequence `\s' treated as plain `s'
  this/pathname/contains/spa ces/and/backslashes
  </code></pre>
  
  <p>This worked, but awk eats the backslash. As you can see above, echo prints it but awk doesn't.</p>
  
  <pre><code>echo "this/pathname/contains/spa ces/and/back\\slashes" | ./escape.sh | xargs -d'\n' -n1 -I{} bash -c 'echo "{}"; echo whatever | gawk "{printf \"{}\"}"'
  this/pathname/contains/spa\ ces/and/back\slashes
  gawk: warning: escape sequence `\ ' treated as plain ` '
  gawk: warning: escape sequence `\s' treated as plain `s'
  </code></pre>
  
  <p>Next I tried escaping the filenames using escape.sh</p>
  
  <pre><code>#!/bin/bash
  xargs -d'\n' -n1 -I{} bash -c 'echo $(printf "%q" "{}")'
  </code></pre>
  
  <p>Now there's a double backslash in there but awk still complains.</p>
  
  <pre><code>echo "this/pathname/contains/spa ces/and/back\\slashes" | ./escape.sh | xargs -d'\n' -n1 -I{} bash -c 'echo "{}"; echo whatever | gawk -v VAR=$(printf "%q" "{}") "{printf VAR}"'
  this/pathname/contains/spa\ ces/and/back\slashes
  gawk: ces/and/back\\slashes
  gawk:        ^ syntax error
  gawk: ces/and/back\\slashes
  gawk:         ^ unterminated regexp
  </code></pre>
  
  <p>Now awk said some nonsense about some unterminated regexp.</p>
  
  <p>Any ideas? Thanks!</p>