0

I have a file where I have a bunch of server IPs ( either null or with some IP)

Scenario 1(File contents):

export Server1=""
export Server2=""

Scenario 2:

export Server1="10.10.10.1"
export Server2="10.10.10.2"

In both of the above cases I want to substitute the values for Server1 and Server2. I tried the following

Server1="11.11.11.1"
Server2="11.11.11.2"
sed -i -e 's/export Server1=""/export Server1=\$Server1/g' file.txt
sed -i -e 's/export Server2=""/export Server2=\$Server2/g' file.txt

For the first scenario the file gets replaced with the string instead of the value for vars

File content after substitution
export Server1=$Server1
export Server2=$Server2

I tried escaping the "$" character but it didnt work. What am I missing?

skorada
  • 351
  • 1
  • 3
  • 13

1 Answers1

0

Would something like this work?

Server1="111.111.111.111"
echo Server=Server1 | sed -e "s/Server1/$Server1/g"

Which gives as an output:

Server=111.111.111.111
Vinicius Placco
  • 1,573
  • 2
  • 9
  • 23