Using xmlstarlet, how do I change the value of an element

前端 未结 1 861
天命终不由人
天命终不由人 2021-01-20 14:45

Using xmlstarlet how can replace the value for all instances of ThreadGroup.num_threads please?

Before

 

        
1条回答
  •  终归单人心
    2021-01-20 15:06

    You can du this with xmlstarlet ed -u. Specify an XPath expression and then set the new value with -v:

    xmlstarlet ed -u '/ThreadGroup/stringProp[@name="ThreadGroup.num_threads"]' \
                    -v 99999 file.xml
    

    (Depending on the rest of your XML file, you may have to modify the XPath expression to be more specific and account for more nesting)

    Here's a complete example:

    $ cat file.xml
    
      continue
      
        false
        778
      
      99999
      66
      44
      55
      false
      77
      0
    
    
    $ xmlstarlet ed -u '/ThreadGroup/stringProp[@name="ThreadGroup.num_threads"]' \
                    -v 99999 file.xml
    
    
      continue
      
        false
        778
      
      99999
      66
      44
      55
      false
      77
      0
    
    

    0 讨论(0)
提交回复
热议问题