2

I want to replace '\'' in a text file to another word or character using sed command.

Tried using sed "s/'\''/×/g" but it doesn't work.

Anyone know the solution?

1 Answer 1

6

If you want to replace the literal text '\'' you would need

sed "s/'\\\\''/new text/g"

The \ needs to be escaped as \\ to represent itself in a regular expression, then you have to double up each of those backslashes since they are part of a double quoted string. You need to use a double quoted string since you want to match single quotes (and a single quoted string can't contain single quotes).

Alternatively:

sed "s/'[\\]''/new text/g"

Where [\\] would be converted to [\] due to the double-quoting of the string before it's given to sed. A backslash in a bracketed expression in a regular expression is always literal.


Your command

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

is functionally the same as

sed "s/'''/×/g"

and will replace any triple single quote with the character ×.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .