Pergunta

I have a following requirement

String 1 : http://gaa-dev.gk.gbcd:9701/analytics

String 2 : https://gaa-prod.gk.gbvd/analytics

There were around 40 different locations in various files(xml content) under /home/gaauser

I want String1 to be REPLACED BY String2

Tried SED, but no luck and I am struck now. Any inputs greatly appreciated.

thanks

Foi útil?

Solução

Two fixes are needed:

  • Since you have / in your strings, it is recommended to use a different delimiter or you need to tell sed that it is not a delimiter by escaping them.
  • Since you are using variables, use double quotes to allow them to interpolate.

str1='http://gaa-dev.gk.gbcd:9701/analytics'
str2='https://gaa-prod.gk.gbvd/analytics'

echo 'http://gaa-dev.gk.gbcd:9701/analytics' | sed "s/$str1/$str2/"
sed: -e expression #1, char 11: unknown option to `s'

echo 'http://gaa-dev.gk.gbcd:9701/analytics' | sed "s|$str1|$str2|"
https://gaa-prod.gk.gbvd/analytics
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top