0

i am trying to replace a single line in an existing file as

sed -i -e 's/# elasticsearch.url: "http://localhost:9200"/elasticsearch.url: "http://myOwnHost:9200"/g' config/kibana.yml

but i get an error

sed: -e expression #1, char 32: unknown option to `s'

i can figure out how and what to escape here. I am quite new to sed.

AbtPst
  • 7,778
  • 17
  • 91
  • 172
  • 2
    Does this answer your question? [How to pass a variable containing slashes to sed](https://stackoverflow.com/questions/27787536/how-to-pass-a-variable-containing-slashes-to-sed) – tripleee Sep 25 '20 at 09:25

2 Answers2

2

In your sed statement the / character is used a separator. e.g. s/search/replace/g. Since you have /s in your string it is messing things up. While / is usually used as the separator, you can use other characters. In your case I would use a pipe | e.g. s|search|replace|g. Alternatively you can use / and escape the slashes in your strings: \/, but that gets messy.

Dan
  • 10,614
  • 5
  • 24
  • 35
0

You have to escape the forward slash characters with backslashes!

sed -i -e 's/# elasticsearch.url: "http:\/\/localhost:9200"/elasticsearch.url: "http:\/\/myOwnHost:9200"/g' config/kibana.yml
Bill Butler
  • 479
  • 3
  • 16