xmlstarlet replace value after pattern

后端 未结 2 453
忘掉有多难
忘掉有多难 2021-01-28 08:07

I have a pom.xml, that I want to change the properties values for tags that starting in a certain pattern.

I usually use xmlstarlet to manipulate XML bu

相关标签:
2条回答
  • 2021-01-28 08:58

    I don't have xmlstartet but I can help with sed

    sed -ibak 's/\(<company\.mgrid\.[^>]*>\)0.8-SNAPSHOT/\10.9-SNAPSHOT/' pom.xml
    

    will do the job and backup your original file in pom.xml.bak if needed. I you dont want this backup file, remove bak after the i flag.

    0 讨论(0)
  • 2021-01-28 08:59

    What you are interested in is the Xpath function starts-with. It is a standard function since Xpath 1.0. This allows you to do :

    $ xmlstarlet ed -N N="http://maven.apache.org/POM/4.0.0"        \
                    -u "//N:*[starts-with(name(),'company.mgrid')]" \
                    -v "0.9-SNAPSHOT" pom.xml
    
    0 讨论(0)
提交回复
热议问题