Script to populate (2) values in .XML

Good Afternoon Team -

I"m asking for assistance on a piece of code to populate two values in an XML file. I have it working perfectly using CScript for DOS, but I have a need to do that same process in a Linux environment.

Here is the XML I need to modify:

<?xml version="1.0" encoding="UTF-8"?>
<Package>
    <LOCALE>en_US</LOCALE>
    <User name="" password=""/>
    <Task>
        <Source type="Application" product="HP" project="Default Application Group" application="GENJBAPP"/>
        <Target type="FileSystem" filePath="/HP-GENJBAPP"/>
        <Artifact recursive="true" parentPath="/Configuration" pattern="*"/>
        <Artifact recursive="true" parentPath="/Essbase Data" pattern="*"/>
        <Artifact recursive="true" parentPath="/Global Artifacts" pattern="*"/>
        <Artifact recursive="true" parentPath="/Plan Type" pattern="*"/>
        <Artifact recursive="true" parentPath="/Relational Data" pattern="*"/>
        <Artifact recursive="true" parentPath="/Security" pattern="*"/>
    </Task>
</Package>

I need to add a value in-between the " symbols for User name as well as a password for password.

Thank you for your time!

Is this what the XML really looks like, or is it actually a lot bigger and messier?

Hi Corona -

This is the entire XML.

Thanks!

sed "s/name=\"\" Password=\"\"/name=\"somename\" password=\"somepassword\"/" inputfile > outputfile

Hi Corona -

It seems to just be giving me an exact copy of the original file. Any ideas?

Hi,

your input contains small p in password so try the below one:

sed "s/name=\"\" password=\"\"/name=\"somename\" password=\"somepassword\"/" inputfile > outputfile
1 Like