-1

I am trying to use this to replace all backslashes with double quotes.

sed -e "s/'\\\\''/\"/g" nomefile

this doesn't do anything.

Input: "prova d\"amico"

Desired output: "prova d""amico"

realtebo
  • 23,922
  • 37
  • 112
  • 189
  • Does this answer your question? [Replacing some characters in a string with another character](https://stackoverflow.com/questions/2871181/replacing-some-characters-in-a-string-with-another-character) – 0stone0 Jan 17 '23 at 16:04
  • 1
    Your `sed` code is not looking for backslashes. It's looking for backslashes surrounded by single quotes, and followed by a second single quote. – Konrad Rudolph Jan 17 '23 at 16:06

2 Answers2

2
sed -e 's/\\/"/g'

Will replace all / with "


Your issue is in the first part: \\\''/, you're looking for ' surrounded /, but you just need \\ for an escaped \


➜ cat input
"prova d\"amico"
➜ 
➜ sed -e 's/\\/"/g' input
"prova d""amico"
➜ 
0stone0
  • 34,288
  • 4
  • 39
  • 64
1

There's a command specifically for global character substitutions ("transliterations"), y:

sed 'y/\\/"/'

where \ has to be escaped with another \.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116