Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed: -e expression #1, char 23: unknown option to `s' [duplicate]

Tags:

sed

I'm trying to use sed to update a config file using a bash script. I have a similar sed command right above this one in the script that runs fine. I can't seem to figure out why this is breaking:

sed -i.bak \
    -e s/"socketPath:'https://localhost:9091'"/"socketPath:'/socket'"/g \
    $WEB_CONF

Any ideas?

like image 541
Alexander Rolek Avatar asked Mar 04 '14 20:03

Alexander Rolek


People also ask

Which regex does sed use?

As Avinash Raj has pointed out, sed uses basic regular expression (BRE) syntax by default, (which requires ( , ) , { , } to be preceded by \ to activate its special meaning), and -r option switches over to extended regular expression (ERE) syntax, which treats ( , ) , { , } as special without preceding \ .


2 Answers

Escape your slashes in the pattern or use a different delimiter like this:

sed -i.bak \
-e s%"socketPath:'https://localhost:9091'"%"socketPath:'/socket'"%g \
$WEB_CONF
like image 197
aragaer Avatar answered Oct 06 '22 01:10

aragaer


The quotes and double quotes are causing problems. You are using them in view of the slashes in the string. In sed you can use another delimiter, such as a #.

sed -e 's#socketPath:https://localhost:9091#socketPath:/socket#g' \
$WEB_CONF
like image 21
Walter A Avatar answered Oct 06 '22 01:10

Walter A