Comparing delta values of one xml file in other xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing delta values of one xml file in other xml file
# 1  
Old 11-20-2013
Comparing delta values of one xml file in other xml file

Hi All,


I have two xml files.

One is having below input
Code:
 
<NameValuePair>
            <name>Daemon</name>
            <value>tcp:7474</value>
        </NameValuePair>
        <NameValuePair>
            <name>Network</name>
            <value></value>
        </NameValuePair>
        <NameValuePair>
            <name>Service</name>
            <value>7474</value>
        </NameValuePair>
        <NameValuePair>
            <name>TestString</name>
            <value>Test</value>
        </NameValuePair>

Second is having :-

Code:
 
<KeyValuePairs>
<Key>TestString</Key>
<Value>Test12_Pollings</Value>
</KeyValuePairs>

I have to read the second file, In that need to read Key Value "TestString" and check if it just contain in the second file and generate the success as output.
# 2  
Old 11-26-2013
Well behaved xml can be mined with text tools like sed and awk. For instance:
Code:
sed -n '
    s/.*<Key>\([^<]*\)<.*/\1/p
  ' file2

says do not print unless commanded, substitute for a line with the Key Element opener, content and any element closer just the content and print it. Note that the regex has .* on both ends to sweep away all else on the line.
# 3  
Old 11-27-2013
Like this ?
Code:
$ cat <<test | awk '/^<Key>/{gsub(/<Key>|<\/Key>/,x);print $0 == Value ? "Success" : "Failure" ;exit}' Value="TestString"
<KeyValuePairs>
<Key>TestString</Key>
<Value>Test12_Pollings</Value>
</KeyValuePairs>
test

Success

for file try this
Code:
$ awk '/^<Key>/{gsub(/<Key>|<\/Key>/,x);print $0 == Value ? "Success" : "Failure" ;exit}' Value="TestString" file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 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. UNIX for Beginners Questions & Answers

How to change values in xml file?

I have xml file like below, i want change the values at default-value place of each argument name using shell script. like where argument name= protocol and default-value=tcp, where argument name =port and default-value= 7223, where argument name = username and default-value=test, example ... (12 Replies)
Discussion started by: s1s2s3s4
12 Replies

3. Shell Programming and Scripting

Grep some values from XML file

Dear community, I have a big XML log file containing several rows splitted by tag: <ActivityLogRecord> and </ActivityLogRecord>. An example below. What I need is read the file and extract some value from each tags and put them into one line (each line for every <ActivityLogRecord> tag). So... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

4. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

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>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

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

6. Shell Programming and Scripting

Extract values from an XML File

Hi, I need to capture all the attributes with delete next to it. The source XML file is attached. The output should contain something like this below: Attributes = legacyExchangeDN Action = Delete Username = Hero Joker Loginid = joker09 OU =... (4 Replies)
Discussion started by: prvnrk
4 Replies

7. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

8. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

9. UNIX for Dummies Questions & Answers

Extracting values from an XML file

Hello People, I have an xml file from which I need to extract the values of the parameters using UNIX shell commands. Ex : Input is like : <Name>Roger</Name> or <Address>MI</Address> I need the output as just : Roger or MI with the tags removed. Please help. (1 Reply)
Discussion started by: sushant172
1 Replies
Login or Register to Ask a Question