0

ERROR: bad flag in substitute command:

I want to update the value of key inside of my config.yml

key: secret

i used this sed command to able to achieve it

sed -i "s/secret/$token/g" config.yml

But when the value of token has "/" at the end I'm encountering that error

something like token="asda213123asndasd/"

Do you how to handle this? Without removing the "/" at the end?

Shua
  • 36
  • 3
  • `cat config.yml | sed "s/secret/$(echo $token | cut -f1 -d'/')/g" > config2.yml` – Elliott Frisch Oct 18 '22 at 12:51
  • @ElliottFrisch you have remove the "/", i want to update it with the original value without remove the / – Shua Oct 18 '22 at 12:58
  • 1
    `cat config.yml | sed $(echo "s/secret/$(echo $token | sed 's/\//\\\//g')/g") > config2.yml` – Elliott Frisch Oct 18 '22 at 13:06
  • Give us about ten lines from config.yml, containing the part you want to extract. Also quote us the exact error that sed is giving you. – petrus4 Oct 18 '22 at 14:15
  • [SOLVED] sed -i "s/secret/$(echo $token | sed 's/\//\\\//g')/g" Thanks @ElliottFrisch – Shua Oct 18 '22 at 15:08
  • @Shua I suggest you consider a different approach for production. The regex I provided is not bulletproof. And what you're doing here looks like it's better as a `bash` script that just does `printf "key: $token\n"` – Elliott Frisch Oct 18 '22 at 15:39

0 Answers0