Script to populate (2) values in .XML

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Script to populate (2) values in .XML
# 1  
Old 10-31-2016
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:

Code:
<?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!
# 2  
Old 10-31-2016
Is this what the XML really looks like, or is it actually a lot bigger and messier?
# 3  
Old 10-31-2016
Quote:
Originally Posted by Corona688
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!
# 4  
Old 10-31-2016
Code:
sed "s/name=\"\" Password=\"\"/name=\"somename\" password=\"somepassword\"/" inputfile > outputfile

# 5  
Old 10-31-2016
Hi Corona -

It seems to just be giving me an exact copy of the original file. Any ideas?
# 6  
Old 10-31-2016
Hi,

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

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

This User Gave Thanks to greet_sed For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract values from xml file script

Hi, please help on this. I want extract values of xml file structure and print in determined way. <ProjectName> --> only appears once <StructList> --> is the top node <Struct> node --> could be more than 1 NameID, STX, STY, PRX, PRY --> appears only 1 time within each <Struct> node... (10 Replies)
Discussion started by: Ophiuchus
10 Replies

2. Shell Programming and Scripting

Getting error while including values in xml tags using shell script

Hi All, Please find the code below where I want to add the variable value in between the XML tags. I am taking one string and my goal is to put them between the xml tags. Ex : in between <name> , <lname> Kindly suggest a correction because while executing this script I am getting and... (8 Replies)
Discussion started by: rajneesh4U
8 Replies

3. Shell Programming and Scripting

AIX UNIX Script to Replace XML Values

Hi - I've seen variations of this same question asked but I have not been able to find an answer that fits my problem. Please direct me to another post if there already is a solution to this. I'm trying to write a Unix script to dynamically iterate through a flat file and replace a value in... (4 Replies)
Discussion started by: ocbit
4 Replies

4. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

5. Shell Programming and Scripting

Passing values to an XML file from shell script

:wall: Hi, I have an XML file with 5 tags. I need to pass values to the XML file from a shell script that will replace values in 2 of the tags. I cannot hardcode the tag values in XML and use replace command in script as the values are likely to change. Please help !!!!!!!!!!! (2 Replies)
Discussion started by: Monalisaa
2 Replies

6. Shell Programming and Scripting

Get multiple values from an xml file using one of the following commands or together awk/perl/script

Hello, I have a requirement to extract the value from multiple xml node and print out the values to new file to compare. Would be done using either awk/perl or some unix script. For example sample input file: ..... ..... <factories xmi:type="resources.jdbc:DataSource"... (2 Replies)
Discussion started by: slbmind
2 Replies

7. UNIX for Dummies Questions & Answers

Trying to execute a script to populate all directories with index.html

Hello, I am trying to create a php file that would copy given index.html file to all directories (and subdirectories) on my site that don't have one. This is to prevent directory listings on nginx. This index.html file is placed in the /populate directory and looks like this: <html> <head>... (7 Replies)
Discussion started by: teletubby
7 Replies

8. Shell Programming and Scripting

Shell script to populate an array from a csv file

Hi Guys, I've got a script that runs and collects statistics from one of our machines and outputs the data into a csv file. Now, that script runs fine and I managed to create another one (with a lot of help from this forum!!) to trim the csv file down to all the data that I need, rather than all... (9 Replies)
Discussion started by: jimbob01
9 Replies

9. Shell Programming and Scripting

Change values in Log4j.xml using ksh script

Hi, I am new to UNIX and shell scripting. I have to create a shell script(ksh) which parses log4j.xml file for a given webservice name and change the corresponding value from INFO to DEBUG or vice-versa. My log4j.xml looks like:- <!-- Appender WEBSERVICENAME--> <appender... (3 Replies)
Discussion started by: sanjeevcseng
3 Replies

10. Shell Programming and Scripting

KSH Script to Get the <TAG Values> from an XML file

Hi All, I am new to Unix I need a KSH script to get the values from XML file to write to a temp file. Like the requirement is from the below TAG <MAPPING DESCRIPTION ="Test Mapping" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1"> I need the MAPPING DESCRIPTION... (3 Replies)
Discussion started by: perlamohan
3 Replies
Login or Register to Ask a Question