Search code examples
xmlbashshellspacexmlstarlet

space character between quotes in bash script using XMLStarlet


I'm trying to edit my xml file with a script in bash using the tool XMLStarlet. So I want to delete a complete tag of my file, my problem is in the syntaxe of my command as following:

xmlstarlet ed -d "/properties/structure name=\"preference\"" $1

The tag is < structure name="preference" >

My error is: XPath error : Invalid expression /properties/structure" "name="preference" The error is pointing on the first quote (")

I try to insert quote, backslash to make the space character acceptable but I don't find the way to make it works. Can someone please help me on this subject? I didn't find yet a topic talking about this.

Thanks by advance


Solution

  • From:

    <properties>
        <bla name="preference" >
        </bla>
        <structure name="preference" >
        </structure>
        <structure name="xxx" >
        </structure>
    </properties>
    

    the:

    xmlstarlet ed -d '/properties/structure[@name="preference"]'
    

    produces

    <?xml version="1.0"?>
    <properties>
      <bla name="preference">
        </bla>
      <structure name="xxx">
        </structure>
    </properties>