Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

i am looking for a way to replace a string in a file with a string that contains a slash by using sed.

echo $srcText | sed "s/XPLACEHOLDERX/$connect"

the result is

sed: -e Expression #1, Character 32: Unknown option for `s'
share|improve this question

2 Answers 2

up vote 25 down vote accepted

Use another character as delimiter in the s command:

echo $srcText | sed "s|XPLACEHOLDERX|$connect|"

Or escape the slashes with parameter expansion:

echo $srcText | sed "s/XPLACEHOLDERX/${connect//\//\/}/"
share|improve this answer
Awsome solution! Didn't know sed is that flexible =) – martin Jun 1 '12 at 12:34
+1 for second way. first one does not work on freebsd. – ibrahim Jul 8 '14 at 11:11

If your shell supports it:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.