Home > Enterprise >  Escape twice special characters using sed
Escape twice special characters using sed

Time:10-20

I have the following string variable defined in bash as version

Uploaded registry/version1.3.1

I need to escape the / twice so that the string looks like:

registry\\/version1.3.1

Is there a way to use sed to find and replace all / to \\/?

CodePudding user response:

One backslash is used to change an argument to text or vice versa.

echo 'Uploaded registry/version1.3.1' | sed 's/\//\\\\\//g'
Uploaded registry\\/version1.3.1

In this case you need \\ for one backslash and \/for a slash.

  • Related