Visit The New, Modern Unix Linux Community


awk to retrieve the particular value from a same list of xml tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to retrieve the particular value from a same list of xml tags
# 1  
Power awk to retrieve the particular value from a same list of xml tags

Hi All,

I have the following code in one of my xml file:

Code:
<com:parameter>
	<com:name>secretKey</com:name>
	<com:value>31XA874821172E89B00B1C</com:value>
</com:parameter>
<com:parameter>
	<com:name>tryDisinfect</com:name>
	<com:value>false</com:value>
</com:parameter>
<com:parameter>
	<com:name>scannerThreadCount</com:name>
	<com:value>10</com:value>
</com:parameter>

Now, I want to retrieve the <com:value> for "secretKey" Parameter. Please help me out..
# 2  
Code:
awk '$0 ~ "<com:name>secretKey<\/com:name>" {getline;FS=">|<";print $3}' file

# 3  
Quote:
Originally Posted by shamrock
Code:
awk '$0 ~ "<com:name>secretKey<\/com:name>" {getline;FS=">|<";print $3}' file


Throwing the following error while executing the awk command:
Quote:
awk: warning: escape sequence `\/' treated as plain `/'
# 4  
Code:
awk -F"<|>" '/<com:name>secretKey</ && getline{print $3}' infile

This User Gave Thanks to Scrutinizer For This Post:
# 5  

if the code is in the following:

Code:
<name>Email Address Encryption</name>
      <className>com.ciphercloud.tokenizers.impl.EmailAddressEncryptorImpl</className>
<tokenWrapConfig>
      <name>Base36</name>
      <scheme>0</scheme>
      <version>0</version>
      <prefix>zqx1</prefix>
      <suffix>1xqz</suffix>
</tokenWrapConfig>

how to retrieve the "Email Address Encryption" value ie., first <name> value using <scheme> tag from the above code?Smilie

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #287
Difficulty: Medium
AIX 7.2 was initially released on December 1, 2013.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. Shell Programming and Scripting

How to retrieve values from XML file and update them in the same position! PLEASE HELP?

Good Day All Im quiet new to ksh scripting and need a bit of your help. I am attempting to write a script that reads in an XML and extracts certain field values from an XML file. The values are all alphanumeric and consist of two components: e.g "Test 1". I need to to create a script that... (2 Replies)
Discussion started by: JulioAmerica
2 Replies

3. Red Hat

Error: Cannot retrieve repository metadata (repomd.xml) for repository: InstallMedia.

Most of my commands are returning this error on RHEL 6 64 bit: Also I tried installing many sofwtares, but it fails to correctly work. For example I treid installing dos2unix: # rpm -ivh dos2unix-5.3.3-5.ram0.98.src.rpm 1:dos2unix warning: user mockbuild does not... (0 Replies)
Discussion started by: India_2014
0 Replies

4. Shell Programming and Scripting

How to add Xml tags to an existing xml using shell or awk?

Hi , I have a below xml: <ns:Body> <ns:result> <Date Month="June" Day="Monday:/> </ns:result> </ns:Body> i have a lookup abc.txtt text file with below details Month June July August Day Monday Tuesday Wednesday I need a output xml with below tags <ns:Body> <ns:result>... (2 Replies)
Discussion started by: Nevergivup
2 Replies

5. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

6. Shell Programming and Scripting

awk and or sed command to sum the value in repeating tags in a XML

I have a XML in which <Amt Ccy="EUR">3.1</Amt> tag repeats. This is under another tag <Main>. I need to sum all the values of <Amt Ccy=""> (Ccy may vary) coming under <Main> using awk and or sed command. can some help? Sample looks like below <root> <Main> ... (6 Replies)
Discussion started by: bk_12345
6 Replies

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

8. Shell Programming and Scripting

how to retrieve specific parameters using a xml tag

Hi, I have the following code in my xml file: <aaaRule loginIdPattern=".*" orgIdPattern=".*" deny="false" /> <aaaRuleGroup name="dpaas"> <aaaRule loginIdPattern=".*" orgIdPattern=".*" deny="false" /> I want to retrieve orgIdPattern and loginIdPattern parameter value based on... (2 Replies)
Discussion started by: mjavalkar
2 Replies

9. Shell Programming and Scripting

How to retrieve value from xml tags

hello, I have a file that have lines that contains xml tags. for each line, i want to retrieve the value from the following xml tags and output it to another file with the values only, comma seperated. what is the best way to do this? again, the string is all in 1 line one, though it has many... (9 Replies)
Discussion started by: davidsouk
9 Replies

10. Shell Programming and Scripting

Read content between xml tags with awk, grep, awk or what ever...

Hello, I trying to extract text that is surrounded by xml-tags. I tried this cat tst.xml | egrep "<SERVER>.*</SERVER>" |sed -e "s/<SERVER>\(.*\)<\/SERVER>/\1/"|tr "|" " " which works perfect, if the start-tag and the end-tag are in the same line, e.g.: <tag1>Hello Linux-Users</tag1> ... (5 Replies)
Discussion started by: Sebi0815
5 Replies

Featured Tech Videos