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
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.