To read xml value depending on property


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To read xml value depending on property
# 1  
Old 08-04-2010
To read xml value depending on property

Hi have some xml like this
Code:
<example>
    <Cell Name="Cell1" ConfigureHost="claas" Role="APPSERV,BACKEND">
      <Node Name="aaaaa" Role="APPSERV,BACKEND,CLM"/>
      <Node Name="vvvv" Role="APPSERV,BACKEND"/>
      <Mercury Type="default" FQDN="ssssss" 
PrimaryReturnFQDN=""/>
    </Cell>
    
  </example>

From shell i want to do somethign like this .If r Role="APPSERV,BACKEND,CLM" i want to set a variable v=aaaa
and Role="APPSERV,BACKEND" set variable k=vvvv

Please help regarding this I am new to shell

Thanks

Last edited by Franklin52; 08-04-2010 at 06:03 AM.. Reason: Please use code tags!
# 2  
Old 08-04-2010
Here is one solution using grep:
Code:
#!/bin/bash

if grep -q "Node Name=\"aaaaa\" Role=\"APPSERV,BACKEND,CLM\"" file
then
    v="aaaa"
fi
if grep -q "Node Name=\"vvvv\" Role=\"APPSERV,BACKEND\"" file
then
    k="vvvv"
fi

echo "Variable v set to: $v"
echo "Variable k set to: $k"


Last edited by pludi; 08-04-2010 at 04:05 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file excluding XML in it

Hi , I have a file like below.I want all the content in a single line excluding the XML.How can i proceed? t=21 y=23 rg=xyz ..... <xmlstarts> . . <xmlends> lk=99 lo=09 (3 Replies)
Discussion started by: chetan.c
3 Replies

2. Shell Programming and Scripting

[SOLVED] Read XML for solaris

Hello I have this script that works fine in Linux But not on sun solaris. Can some one help me with the awk syntax for solaris. Linux: awk -F $0~/DBURL/ {print $7} /tmp/test.xml---------- Post updated at 11:16 AM ---------- Previous update was at 11:05 AM ---------- Sorry guys i got the... (0 Replies)
Discussion started by: pradeepmacha
0 Replies

3. Shell Programming and Scripting

Report a missing property and property value mis match script.

Hi All, I have 2 properties files - one is a master templete and other one is a node specific properties file, I need to comapre these 2 properties files and make sure the node Specific properties file contains all the properties in the master temple properties file else report the missing... (5 Replies)
Discussion started by: jayka
5 Replies

4. Shell Programming and Scripting

Help on awk to read xml file

Hello, I have a xml file as shown below. I want to parse the file and store data in variables. xml file looks like: <TEST NAME="DataBaseurl">jdbc:oracle:thin:@localhost:1521:ora10</TEST> <TEST NAME="Databaseuser">Pradeep</TEST> ...... and many other such lines i want to read this file and... (2 Replies)
Discussion started by: pradeepmacha
2 Replies

5. Shell Programming and Scripting

script to read XML file

Dear All, I have one log file and it contains lot of XML as below. ... (1 Reply)
Discussion started by: murtujak
1 Replies

6. Shell Programming and Scripting

Read data in XML file

Hello Everybody, I have a question on reading the data from XML file through KSH shell script. In the below file I need to collect the patient control no and its respective insured id. I need to have pair of these values in single line separated by some special character, so that I could use... (2 Replies)
Discussion started by: swame_sp
2 Replies

7. Shell Programming and Scripting

URGENT: Script/Function needed to read text property files in block wise

Hi, Iam in a need for a script/function in KSH where I want to read a text file (property file) in block by block. Here is the example: Heading Name Descripton Block Block1 Value1 Description Property Name Value Property Name Value Property Name Value Property Name Value Property Name... (7 Replies)
Discussion started by: ysreenivas
7 Replies

8. UNIX Desktop Questions & Answers

read XML xml element with REGEXP

Hi, I would need to read an xml element from an xml file to a local variable. Please could you help me with a shell script to get so? Considering that I have a file called file.xml like below: <header> <description>This is the description</description> <content>This is the... (2 Replies)
Discussion started by: oscarmon
2 Replies

9. Shell Programming and Scripting

Problem printing the property of xml file via shell script

Hi, I have a config.xml which cointains the tags like <CONFIG> <PROPERTY name="port" value="1111"/> <PROPERTY name="dbname" value="ABCDE"/> <PROPERTY name="connectstring" value="xyz/pwd"/> </CONFIG> This file is in some directory at UNix box. I need to write a... (4 Replies)
Discussion started by: neeto
4 Replies

10. Shell Programming and Scripting

Read xml file

Iam new to shell script. How to read xmlfile using shellscript(without awk),and Store record by record in file . My xml file: <root> <header> <HeaderData1>header1</HeaderData1> <HeaderData2>header2</HeaderData2> </header> <detailsRecord> ... (2 Replies)
Discussion started by: ram2s2001
2 Replies
Login or Register to Ask a Question