I doubt that your sed
command works on RedHat as the spacing in the regular expression wouldn't match in the example document that you are showing. Also, parsing or modifying a document written in a structured document format such as XML is at best hazardous with a line-oriented text editing tool like sed
.
The second issue is your use of the non-standard -i
option. The portable ways of doing in-place editing are described in the Q/A How can I achieve portability with sed -i (in-place editing)?
Assuming that the XML document is well-formed, you would normally use a command line XML parser to modify the contents of the document.
One such command line XML parser is xmlstarlet
.
xmlstarlet ed -u '//config' -v 3242352353242342424 file.xml
This would set the value of all config
nodes to the string 3242352353242342424
(this value will be properly encoded by xmlstarlet
if needs be). Any previous value will be discarded, any attributes to the config
nodes will be retained.
The modified document would be written to standard output, so you could redirect it into a new file. There is also an --inplace
option that you would use after the sub-command ed
on the command line.
xmlstarlet
is known to work on both Linux and AIX.
-i
option, redirect the output of yoursed
to a temporary file and then move that temp file to the original path. – Philippos Apr 27 '21 at 14:18