title: How to pass base64 encoded content to sed?
body: <p>Variable XFILEBASE64 has base64 encoded content and I want to replace some string with that base64 content.</p>
  
  <p>Sure enough base64 is packed with special characters, and I've tried $'\001' as delimiter, still getting the error message. Any suggestions?</p>
  
  <pre><code>XFILEBASE64=`cat ./sample.xml | base64`
  cat ./template.xml  | sed "s$'\001'&lt;Doc&gt;###%DOCDATA%###&lt;\/Doc&gt;$'\001'&lt;Doc&gt;${XFILEBASE64}&lt;\/Doc&gt;$'\001'g"
  &gt; sed: -e expression #1, char 256: unterminated `s' command
  </code></pre>
  
  <p>EDIT: Looks like problem has nothing to do with sed, it must be hidden in base64 operations.</p>
  
  <p>sample.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;a&gt;testsdfasdfasdfasfasdfdasfdads&lt;/a&gt;     
  </code></pre>
  
  <p>To reproduce the problem:</p>
  
  <pre><code>foo=`base64 ./sample.xml`
  echo $foo | base64 --decode
  
  &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;base64: invalid input
  </code></pre>