how to search a value from a xml


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to search a value from a xml
# 1  
Old 01-09-2009
how to search a value from a xml

I have a file which has following content.

<drdata_export>
<drdata>
<tags>
<timestamp>1231420399:617026000</timestamp>
<from_ip_address>67.178.40.168</from_ip_address>
<to_ip_address>76.96.6.6</to_ip_address>
<cause_code>502</cause_code>
<protocol_type>2001</protocol_type>
<sip_from_tag>1_1103_f4755_5u06_CtkMB7E42B</sip_from_tag>
<sip_from_display_name>RUFF LINDA</sip_from_display_name>
<sip_to_tag>aprqngfrt-1flif20000020</sip_to_tag>
<call_id>2030470795@CHCIILNQPS1AA.SSG.COMCAST.NET</call_id>
<request>INVITE</request>



actaully i want to extract the value 2001 which is next to <protocol_type> .


can any one please help me on this?
# 2  
Old 01-09-2009
Code:
sed -n 's/<protocol_type>\([^<]*\)<.*/\1/p' infile
2001

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed search and replace after xml tag

Hi All, I'm new to sed. In following XML file <interface type='direct'> <mac address='52:54:00:86:ce:f6'/> <source dev='eno1' mode='bridge'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> ... (8 Replies)
Discussion started by: varunrapelly
8 Replies

2. Shell Programming and Scripting

How can I extract XML block around matching search string?

I want to extract XML block surrounding search string Ex: print XML block for string "myapp1-ear" surrounded by "<application> .. </application>" Input XML: <?xml version="1.0" encoding="UTF-8"?> <deployment-request> <requestor> <first-name>kchinnam</first-name> ... (16 Replies)
Discussion started by: kchinnam
16 Replies

3. Shell Programming and Scripting

Search and replace the string with new word using xml tags

Hi All i need to replace the url1 inside <remote> tag in below xml in first instance and in the second instance with url2. any help appreciated <locations> <hudson.scm.SubversionSCM_-ModuleLocation> <remote>https://svn2015.com/svn/repos/internalshard</remote> ... (4 Replies)
Discussion started by: madankumar.t@hp
4 Replies

4. Shell Programming and Scripting

Need an efficient way to search for a tag in an xml file having millions of rows

Hi, I have an XML file with around 1 billion rows in it and i am trying to find the number of times a particular tag occurs in it. The solution i am using works but takes a lot of time (~1 hr) .Please help me with an efficient way to do this. Lets say the input file is <Root> ... (13 Replies)
Discussion started by: Sheel
13 Replies

5. UNIX for Advanced & Expert Users

Search in xml tags

I have a xml file like below. I want to search in <msg>, if found corresponding tag path needs to fetch. for eg: for the message 'RM1659 Boeing Exception Management' it should return /trunk/talend/source/SITA_SP7/Job_Designs/DeferredOutputs/SmartViewFiles/DO_Smartview.zip For message it can... (2 Replies)
Discussion started by: svenkatareddy
2 Replies

6. Shell Programming and Scripting

Search and replace in xml file using awk..

Hi All, I have xml file,i am tring to use awk to search pattern as: <Password>x</Password> and Replace with: <Password>y</Password> please any one can help to solve this using awk and awk only. (4 Replies)
Discussion started by: islam2666
4 Replies

7. Shell Programming and Scripting

Search for word in a xml file and replace it with something else

Hello Unix Users, I am very new to Unix so I am not sure how do I do the following. I need a script such that when I type the following in the command prompt > . scriptName.sh wordToBeReplaced DirectoryLocation will find the word someword located in a somefile.xml in DirectoryLocation... (8 Replies)
Discussion started by: 5211171
8 Replies

8. Shell Programming and Scripting

search a word in a xml file and print the out put

hi , i m having a html file and this file looks like this <ssl> <name>PIA</name> <enabled>true</enabled> <listen-port>39370</listen-port> </ssl> <log> <name>PIA</name> </log> <execute-queue> <name>weblogic.kernel.Default</name> ... (7 Replies)
Discussion started by: becksram123
7 Replies

9. Shell Programming and Scripting

how to search xml tags using unix shell

Hi All, Good day Here is my data: <Journal> <JournalCode>2</JournalCode> <JournalType>L</JournalType> <JournalEntry>SG</JournalEntry> <JournalAmount>-0.05</JournalAmount> </Journal> Problem: 1) I need to query the above tags in xml. Which is from the header <Journal>... (4 Replies)
Discussion started by: lutinoman
4 Replies

10. UNIX for Dummies Questions & Answers

Search for xml tags in a file

Hi, I need to search for a pattern like : <A:UserAttr Name="ACTIVITY_ID"> <A:Value>1111120</A:Value> </A:UserAttr> Let us the there is a dir /tmp that contains 5 xml file. each of them multiple above tags in the file. If found all the three line would be... (2 Replies)
Discussion started by: tictactoe
2 Replies
Login or Register to Ask a Question