I have the following attribute:
How can I replace everything inside
<client-version></client-version> to only change the value (1.2.8)?
So it would be:
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You would use an XML parser to do this. For example
xmlstarlet (a command line XML tool):
$ xmlstarlet ed -u '//client-version' -v '1.2.9' file.xml <?xml version="1.0"?> <client-version>1.2.9</client-version>
The above command would locate all occurrences of the
client-version document node and change their values to the string
To only change the ones that are
1.2.8, you would use
xmlstarlet ed -u '//client-version[text() = "1.2.8"]' -v '1.2.9' file.xml
Redirect the output to a new file, inspect it and rename it to the original filename, or run
xmlstarlet with its
--inplace options to edit the file in-place.