dataviews
dataviews

Reputation: 3100

remove backslash only from quote character using sed

I have string: this is a [\"sample\"] sample\'s.

What would be the correct way to remove backslashes from the double quote, preserving the double quote.

Expected output: this is a ["sample"] sample\'s.

I've tested: sed -i 's/\\\"//g' file.txt which is removing the "

Upvotes: 0

Views: 727

Answers (1)

xhienne
xhienne

Reputation: 6134

Your command is almost correct. You just forgot to substitute with a double quote:

sed -i 's/\\"/"/g' file.txt

sed's s command substitutes the first part (between / here) with the second part. The g flag repeats the operation throughout the line. Your mistake was that the second part was empty, thus effectively deleting the whole \" string.

BTW, escaping the double quote is not necessary since your sed command is inside single quotes.

Upvotes: 4

Related Questions