Issue
Variable XFILEBASE64 has base64 encoded content and I want to replace some string with that base64 content.
Sure enough base64 is packed with special characters, and I've tried $'\001' as delimiter, still getting the error message. Any suggestions?
XFILEBASE64=`cat ./sample.xml | base64`
cat ./template.xml | sed "s$'\001'<Doc>###%DOCDATA%###<\/Doc>$'\001'<Doc>${XFILEBASE64}<\/Doc>$'\001'g"
> sed: -e expression #1, char 256: unterminated `s' command
EDIT: Looks like problem has nothing to do with sed, it must be hidden in base64 operations.
sample.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<a>testsdfasdfasdfasfasdfdasfdads</a>
To reproduce the problem:
foo=`base64 ./sample.xml`
echo $foo | base64 --decode
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<base64: invalid input
Solution
The problem was in base64 encoding, -w 0 option of base64 did the trick.
cat ./sample.xml | base64 -w 0
Answered By - user52028778 Answer Checked By - Marilyn (WPSolving Volunteer)