DerZauberer DerZauberer - 9 months ago 51
Bash Question

Use slashes in sed replace

I'm writing a shell script to create some config files.

I also have to replace some patterns in the files and one pattern should get replaced with a path.

So my question is: Is there a way to replace my placeholder webpath with a path without setting backslashes in front of the slashes?

Maybe there is another tool available to do this?


You can use an alternative regex delimiter as a search pattern by backslashing it:

sed '\,some/path,d'

And just use it as is for the s command:

sed 's,some/path,other/path,'

You probably want to protect other metacharacters, though; this is a good place to use Perl and quotemeta, or equivalents in other scripting languages.

From man sed:

  Match lines matching the regular expression regexp.

  Match lines matching the regular expression regexp.
  The  c  may be any character.