Jardalu
Jardalu

Reputation: 231

Replace a double backslash followed by quote (\\') using sed?

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'

Upvotes: 5

Views: 6094

Answers (2)

nu11p01n73R
nu11p01n73R

Reputation: 26667

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

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

Upvotes: 8

Rakholiya Jenish
Rakholiya Jenish

Reputation: 3223

You can also use:

sed "s/\\\\\'/\\\'/g" 

Upvotes: 2

Related Questions