I\'m trying to write a simple Bash script. I have a simple \"template\" variable:
template = \"my*appserver\"
I then have a function (
There are so many posts available online but the one which worked fine for me is as below.
There are 2 ways to achieve this, if you want to replace a string (my old string is with special character :) with another string in a file, then use this:
sed -i '/oldtext:/c\newtext: Rahul' ./printName.txt
Secondly, if you want to search for a string and then replace it with your variable, then do this:
#here im concatinating two key + value(myvariable).
firstkey="oldtext: old"
key="newtext: "
value=$(cat ./variableStoredHere.txt)
key+=$value
result for below command will be oldtext: old
echo $firstkey
result for below command will be will be newtext: Rahul
echo $key
sed -i "s/$firstkey/$key/g" ./printName.txt