I have declared a variable in a file. I want to set the value of this variable, to a variable in a different file. When I tried to use ’sed’ to accomplish this, I encountered an error. The error was, its not getting the value from the old file and just places the variable name in the new file. By changing the command slightly, It works fine. Given below are the commands I used.
OLD-FILE
a=one
NEW-FILE
b=four
$ source OLD-FILE
$ sed -i ’s/b=.*/b=\${a}/’ NEW-FILE #Output : b=${a} #Wrong
$ sed -i ’s/b=.*/b=’$a/ NEW-FILE #Output : b=one #Correct One
very interesting, but I don’t agree with you
Idetrorce
I faced this problem and google search got me here.. thanks da sombai
this works:
a=”hello”
sed -e s/b=.*/b=”$a”/ OLDFILE
do not using -e ’something’ ,while use “” to include the variable
This was exactly what I needed.
MSG2=`echo ${MSG1} | sed ’s/$A/’${START}/g | sed ’s/$B/’${STOP}/g`
echo “${MSG2}”
Now prints exactly what I intended instead of variable names.
Thanks!