How to change specific value of XML attribute using scripting on Mac

后端 未结 1 1445
隐瞒了意图╮
隐瞒了意图╮ 2021-01-20 04:03

I have been tasked to write a script to change a specific value in an XML file on about 1000 Macs. Clearly this needs to be scripted, and preferably only using tools that ar

相关标签:
1条回答
  • 2021-01-20 04:29

    Using awk:

    awk '/<IPv6>/,/<\/IPv6>/ {sub(/Automatic/,"__INACTIVE__")}1' xml_file > new_xml_file
    

    Using sed: In-line editing

    sed -i '/<IPv6>/,/<\/IPv6>/s/Automatic/__INACTIVE__/' xml_file
    

    To add counts in the mix:

    awk '
    /<IPv6>/,/<\/IPv6>/ {sub(/Automatic/,"__INACTIVE__"); if ($0~/__/) count++}1 
    END{ print FILENAME, count >>"countfile"}' xml_file> new_xml_file
    

    The END statement will capture the Filename you ran the script on and the counts of changes in a file called countfile and will keep appending to it for your statistical analysis.

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