When I run:
unzip -p /tmp/document.docx word/document.xml | sed -e 's/<\/w:p>/\\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
It correctly extracts the text from my .docx file.
But when I try to wrap this in a Node.js program as follows:
const spawn = require("child_process").spawn;
const command = "unzip"; ;
const child = spawn("sh", ["-c", "unzip -p /tmp/document.docx word/document.xml | sed -e 's/<\/w:p>/\\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'"]);
const stdout = child.stdout;
const stderr = child.stderr;
const output = "";
stderr.on("data", function(data) {
console.error("error on stderr", data.toString());
});
stdout.on("data", function(data) {
output += data;
});
stdout.on("close", function(code) {
});
I get the following error message:
error on stderr sed: -e expression #1, char 10: unknown option to `s'
How do I fix this error?