how to replace a \' with '' using sed -
i have file test.sql:
'here is' , \' other 'you' and replace \' (escaped single quote) '' (2 singles quotes) postgres , leave other single quotes alone. how this. have tried:
mon mar 16$ sed -i.bak s/\'/''/g test.sql but takes out single quotes.
your enemy in shell quoting. string
s/\'/''/g is mangled shell before given sed. shell, '' empty string, , \' suppresses special meaning of single quotes (so quote actual single quote character). sed sees after processing is
s/'//g ...wich removes single quotes.
there several ways work around problem; 1 of them is
sed -i.bak "s/\\\\'/''/g" test.sql inside doubly-quoted shell string, backslashes need escaped (exceptions exist). means "s/\\\\'/''/g" in shell command translates s/\\'/''/g argument sed. in sed regexes, backslashes need escaping, is, in fact, wanted happen: instances of \' replaced ''.
Comments
Post a Comment