Search code examples
xmlrangexmlstarlet

xmlstarlet delete node with range


I'd to know how to delete a node with range using the command below.

single node delete works fine:

xmlstarlet ed -L -d '//job/input/audio_selector[2]' profile.xml

How to achieve this if I want to delete a node with range.

sample delete a node audio_selector from range 2 to 20:


Solution

  • If you're trying to delete the audio_selector based on position, try:

    xmlstarlet ed -L -d '//job/input/audio_selector[position() >= 2 and 20 >= position()]' profile.xml
    

    If you're trying to delete the audio_selector based on value, try:

    xmlstarlet ed -L -d '//job/input/audio_selector[number() >= 2 and 20 >= number()]' profile.xml