0

I am trying to delete a line from xml file by comparing resource name tab value from same xml file, the below bash script works if I put logfilename as Mansing but gets failed when I keep the value as 'jdbc/test'. Any help?

bash code:

logfilename="jdbc/test"

sed -i "/\<$logfilename\>/d" /home/test/test.xml

test.xml file is as below:

<a>
<Resource name="jdbc/test" auth="container" url="localhost:8080"
<Resource name="Mansing" auth="container" url="localhost:8080"
</a>
techraf
  • 64,883
  • 27
  • 193
  • 198
mansing shinde
  • 445
  • 7
  • 25
  • See here: http://unix.stackexchange.com/questions/32907/what-characters-do-i-need-to-escape-when-using-sed-in-a-sh-script – ceving Dec 02 '16 at 08:34

1 Answers1

1

jdbc/test contains / that is interpreted as a delimiter by the sed command. Try to escape it:

logfilename="jbdc\/test"

or change the default delimiter in your address by prefixing the first new delimiter with \:

sed -i "\~\<$logfilename\>~d" /home/test/test.xml
SLePort
  • 15,211
  • 3
  • 34
  • 44