简体   繁体   中英

Replacing strings with sed in ubuntu

I have a config file with such value:

SITE_URL=http://domain.com

So I am trying to replace it with something like development.local.dev with sed, but not sure how to escape the domain correctly. Tried a lot of something like this:

sed -i -e 's/SITE_URL=http://domain\.com/SITE_URL=development.local.dev/g' .env

But keep getting: sed: -e expression #1, char 19: unknown option to `s'

It is because / is used a regex delimiter and it is used in your search pattern as well.

You can use an alternate delimiter eg ~ in sed :

sed '/^SITE_URL=/s~http://domain\.com~development.local.dev~' file
SITE_URL=development.local.dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM