You could check that the "
is either at the beginning of a line or preceded by a whitespace:
sed -r 's/(^| )"/\1``/g' filename
If your version of sed
doesn't support extended regular expressions, you could say:
sed 's/\(^\| \)"/\1``/g'` filename
For escaping %
and possibly other characters like &
, $
, you could make use of a character class to escape all those in one go:
sed -r 's/([$%])/\\\1/g' filename
The two could be combined too:
sed -r 's/(^| )"/\1``/g; s/([$%])/\\\1/g' filename
EDIT: From your clarification, it seems that you need to say:
sed -r 's/(^| )"/\1``/g;s/"/'"''"'\1/g' filename