I'm trying to sanitize quotes(") in text file by replacing them with \" or an empty string. The replacing must occur in substring delimited by TOKEN placeholders.
Example
# input (example.txt):
Line title "A" - TOKEN some line with "quotation marks"
Line title "B" - TOKEN some line with "another quotation marks"
Line title "C" - TOKEN some "line" TOKEN more "text"
Random "line"
# result (example.txt)
Line title "A" - TOKEN some line with \"quotation marks\"
Line title "B" - TOKEN some line with \"another quotation marks\"
Line title "C" - TOKEN some \"line\" TOKEN more "text"
Random "line"
# Another option
# result (example.txt)
Line title "A" - TOKEN some line with quotation marks
Line title "B" - TOKEN some line with another quotation marks
Line title "C" - TOKEN some line TOKEN more "text"
Random "line"
Preferably without external dependencies(i.e Python,JS) on Linux, so probably sed, awk, bash are best
PS - What I've tried so far is:
sed -iE "s/TOKEN(.+)(\")(.+).*\TOKEN\1\3/g" /tmp/test
But it handles only a single replacement per line
EDIT:
(sorry about late addition after many answers)
- TOKEN is a a delimiter - Added Line title "C" to the example
- No replacement should occur on line without TOKEN - Added Random "line"