3

I have values in txt file

cc.cis.jms.Simulator.CAAMS=CAAM270:CAAM050

Now i want to replace the below value as

cc.cis.jms.Simulator.CAAMS=CAAM270:CAAM050:CAAM250

I tried this:

SIMULATOR='CAAM270:CAAM050'
ADDEDCAAM="$SIMULATOR:CAAM250"
SACTUALVALUE='cc.cis.jms.Simulator.CAAMS='$SIMULATOR
SREPLACEVALUE='cc.cis.jms.Simulator.CAAMS='$ADDEDCAAM

sed -i 's|$SACTUALVALUE|$SREPLACEVALUE|g' $FILE >  /tmp/Bridger/CC_CISConfig.properties

CC_CISConfig.properties file got created in /tmp/Bridger/ path but with no content on it.

I also tried:

sed -i 's|$SACTUALVALUE|$SREPLACEVALUE|g' $FILE >  /tmp/Bridger/CC_CISConfig.properties.txt

But didnt work out. Kindly help

jam
  • 3,640
  • 5
  • 34
  • 50
  • possible duplicate of [Replace a text with a variable (sed)](http://stackoverflow.com/questions/16297052/replace-a-text-with-a-variable-sed) – tripleee Aug 30 '13 at 09:32

1 Answers1

3

You have to use " to substitute your bash variable values in sed expression.

It should be,

sed -i "s|$SACTUALVALUE|$SREPLACEVALUE|g" $FILE >  /tmp/Bridger/CC_CISConfig.properties

Then, You are using -i option. It will change the modification in original file. But, you are redirecting STDOUT to /tmp/Bridger/CC_CISConfig.properties. In this case, nothing to be written to the file. That is why, you are getting empty file.

1) If you want to create a new updated file,

sed "s|$SACTUALVALUE|$SREPLACEVALUE|g" $FILE >  /tmp/Bridger/CC_CISConfig.properties

2) If you want to do the substitution in the same(original) file,

sed -i "s|$SACTUALVALUE|$SREPLACEVALUE|g" $FILE
sat
  • 14,589
  • 7
  • 46
  • 65
  • 1
    if this answer solved your problem, mark this as accepted. more info, [click here](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work?answertab=votes#tab-top). – sat Aug 30 '13 at 10:13