I’m on rhel5 and have the following problem:
I have a function which replaces all the content from a given line with the text i want it to. Everything works fine till i need double quotes to be placed. following is the code:
ReplaceLine()
{
txnFile="File.xml"
if [ "$2" == "enable" ];then
replace="<ref bean=\\"$3\\"/>"
else
replace="<!--<ref bean=\\"$3\\"/>-->"
fi
sed -i "$1s/.*/$replace/" $txnFile
}
$1=line number
$2=enable/disable
$3=string to be put
Current code replaces the given line in the file with this:
<ref bean=beginEventBean/>
What i want is this:
<ref bean="beginEventBean"/>
Notice the missing double quotes. Also i used double quotes in sed as without them the spaces in the variables were causing sed to throw errors.
Please help me understand where i’m going the wrong way. Spent hours on this already.
You forgot to escape the forward slash closing the tag. And you put two many slashes.