4.32. How do I handle Unix shell quoting in sed?
To embed a literal single quote (') in a script, use (a) or (b):
(a) If possible, put the script in double quotes:
sed "s/cannot/can't/g" file
(b) If the script must use single quotes, then close-single-quote
the script just before the SPECIAL single quote, prefix the single
quote with a backslash, and use a 2nd pair of single quotes to
finish marking the script. Thus:
sed 's/cannot$/can'\''t/g' file
Though this looks hard to read, it breaks down to 3 parts:
's/cannot$/can' \' 't/g'
--------------- -- -----
To embed a literal double quote (") in a script, use (a) or (b):
(a) If possible, put the script in single quotes. You don't need to
prefix the double quotes with anything. Thus:
sed 's/14"/fourteen inches/g' file
(b) If the script must use double quotes, then prefix the SPECIAL
double quote with a backslash (\). Thus,
sed "s/$length\"/$length inches/g" file
To embed a literal backslash (\) into a script, enter it twice:
sed 's/C:\\DOS/D:\\DOS/g' config.sys