code-8
code-8

Reputation: 58652

update URL endpoint of specific via sed

I would like to replace a line of this file /Users/jdoe/Sites/vue/app/public/index.html

from

window.API_URL = "anything"

to

window.API_URL = "http://api.local:1234

I tried :

sed -i -e 's/.*window.API_URL.*/window.API_URL = "http://api.local:1234"/g' /Users/jdoe/Sites/vue/app/public/index.html

Kept getting

sed: 1: "s/.window.API_URL./wi ...": bad flag in substitute command: '/'

Upvotes: 0

Views: 43

Answers (1)

cordigliere
cordigliere

Reputation: 66

you need the \ to escape the / in the url, this should work:

sed -i -e 's/.*window.API_URL.*/window.API_URL = "http:\/\/api.local:1234"/g' index.html

also if you prefer awk:

awk -i inplace '/window.API_URL/ {$3=" \"http://api.local:1234\""} 1' index.html

Upvotes: 1

Related Questions