I am trying to get a dns address using curl and I would like to use that dsn address to replace a word in a .js file.
So the .js file contains a word “hostname” and I would like to replace that with the dns address fetched from curl so what I am trying to do is this.
sed 's/hostname/curl -s http://169.254.169.254/latest/meta-data/public-hostname/g' server.js
I get a error message which is sed: -e expression #1, char 26: unknown option to s'
Advertisement
Answer
I just needed to escape the ‘/’ and it works
sed 's/hostname/curl -s http://169.254.169.254/latest/meta-data/public-hostname/g' server.js
If you want to replace inside the file, you can use a temp file
sed 's/hostname/curl -s http://169.254.169.254/latest/meta-data/public-hostname/g' server.js > temp.js mv temp.js server.js
There are better ways to do this, not sure if this meets your needs