0

I am trying to delete a line from XML file using SED. i.e. sed -i "/Mansing/d" /home/test.xml but it deleting both the lines one with having 'Mansing' and other with 'MansingTest' as in Resource name value. Any help? XML file is as below

<a> <Resource name="Mansing" auth="container" url="jdbc:mysql:"" /> <Resource name="MansingTest" auth="container" url="jdbc:mysql:"" /> <c> <Test>tterer</test> </c> </a>

3
  • 2
    Use proper xml aware tools like xmlstarlet and not blunt text processing tools. Commented Nov 28, 2016 at 6:50
  • What's stopping you from changing the search regex to /\"Mansing\"/? But @Inian has a valid point: Use a proper tool for the job. Commented Nov 28, 2016 at 6:50
  • I agree with and appreciate your help. Though xmlstarlet does not work at my end, I will find out what module it requires on machine. Thank you Commented Nov 28, 2016 at 8:38

2 Answers 2

1

With this syntax fixed file.xml

<a>
    <Resource name="Mansing" auth="container" url="jdbc:mysql:" />
    <Resource name="MansingTest" auth="container" url="jdbc:mysql:" />
    <c>
        <Test>tterer</Test>
    </c>
</a>

and xmlstarlet.

xmlstarlet ed -d '//a/Resource[@name="Mansing"]' file.xml

Output:

<?xml version="1.0"?>
<a>
  <Resource name="MansingTest" auth="container" url="jdbc:mysql:"/>
  <c>
    <Test>tterer</Test>
  </c>
</a>
Sign up to request clarification or add additional context in comments.

Comments

0
sed  "/\<Mansing\>/d" filename

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.