When /
is part of a regular expression that you want to replace with the s
(substitute) command of sed
, you can use an other character instead of slash in the command's syntax, so you write, for example:
sed 's,/,\\\\,g'
above ,
was used instead of the usual slash to delimit two parameters of the s
command: the regular expression describing part to be replaced and the string to be used as the replacement.
The above will replace every slash with two backslashes. A backslash is a special (quoting) character, so it must be quoted, here it's quoted with itself, that's why we need 4 backslashes to represent two backslashes.
$ echo /etc/passwd| sed 's,/,\\\\,g'
\\etc\\passwd