5

I am unable to replace double backslash followed by quote \\' in sed. This is my current command

echo file.txt | sed "s:\\\\':\\':g"

The above command not only replaces \\' with \' it also replaces \' with '

How could I just replace exact match?

Input:

'one', 'two \\'change', 'three \'unchanged'

Expected:

'one', 'two \'change', 'three \'unchanged'

Actual:

'one', 'two \'change', 'three 'unchanged'
Jardalu
  • 221
  • 2
  • 9

2 Answers2

8
$ sed "s/\\\\\\\'/\\\'/g" file
'one', 'two \'change', 'three \'unchanged'

Here is a discussion on why sed needs 3 backslashes for one

Community
  • 1
  • 1
nu11p01n73R
  • 25,677
  • 2
  • 36
  • 50
2

You can also use:

sed "s/\\\\\'/\\\'/g" 
Rakholiya Jenish
  • 3,057
  • 15
  • 27