I'm trying to replace \" (backslash doouble quote) by ' (quote) using sed.
sed "s/\\\"/\'/g" file.txt
The command doesn't work as开发者_开发百科 expected. It replaces all the " in the text file, not only the \".
It does the same thing as sed "s/\"/\'/g" file.txt
I'm working on Mac OS X Leopard.
Does any one have a clue?
You're dealing with the infamous shell quoting problem. Try using single quotes around the s//g instead, or add an extra escape:
sed "s/\\\\\"/\'/g"
Quoting issues with bash are fun.
$ cat input "This is an \"input file\" that has quoting issues." $ sed -e 's/\\"/'"'"'/g' input "This is an 'input file' that has quoting issues."
Note that there are three strings butted together to make the sed script:
s/\\"/
'
/g
The first and last are quoted with single quotes, and the middle is quoted with double quotes.
Matthew's command works by joining two strings instead of three:
s/\\"/
'/g
where the first is single-quoted and the second double-quoted.
don't have to use too many quotes. \042 octal is for "
and \047 is octal for single quote
awk '{gsub("\042","\047") }{print}' file
精彩评论