Well, that's what I came to.
First, I learned with ord () what codes are for single and double quotes, and then I used the $ (..) syntax to pass it into an unquoted sed expression. I used XX and yy instead of empty lines. Obviously, this is faaar from the optimal, i.e. They may need to be combined into a single expression, I recommend that you experiment with it. There are several methods to avoid quoting issues, you can also put the sed expression in a separate file so that it is not interpreted by the shell. The ord () / chr () character is also useful when you are trying to deal with single unreadable characters in the output, for example. UTF strings on a console other than UTF.
dtpwmbp:~ pwadas$ echo '"' | perl -pe 'print ord($_) . "\n";' 34 " dtpwmbp:~ pwadas$ echo "'" | perl -pe 'print ord($_) . "\n";' 39 ' dtpwmbp:~ pwadas$ echo \'\" '" dtpwmbp:~ pwadas$ echo \'\" | sed -es/$(perl -e 'print chr(34) . "\n"')/XX/g | sed -es/$(perl -e 'print chr(39) . "\n"')/yy/g yyXX dtpwmbp:~ pwadas$
EDIT (note that this time both characters are replaced with the same string "yy"). There may be some shell utilities for โtranslatingโ characters into character codes and vice versa, i.e. this should be possible without using perl or another language translator.
dtpwmbp:~ pwadas$ echo \'\" | sed -es/[`perl -e 'print chr(34) . chr(39)'`]/yy/g yyyy dtpwmbp:~ pwadas$
and here is another way in the shell, perhaps even simpler
dtpwmbp:~ pwadas$ X="'"; Y='"' ; echo $X$Y; echo $X$Y | sed -e "s/$X/aa/g;s/$Y/bb/g" '" aabb dtpwmbp:~ pwadas$
Piotr wadas
source share