Parse xml in shell script and extract records with specific condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse xml in shell script and extract records with specific condition
# 8  
Old 04-02-2015
I am sorry for multiple posts. Yeah , I am trying with my data file name sample.xml

looks like something i am missing , i used following code
Code:
awk '/^<logentry revision=/{A=1} A{O=O?O ORS $0:$0} /<QC_ID><\/QC_ID>/{print O;B=1;next} B{print $0} /<\/logentry>/{B=0;O=""}' sample.xml



from above data we should be able to see the output <logentry revision="21511"> record ( as QC_ID is null )

---------- Post updated at 02:45 PM ---------- Previous update was at 02:33 PM ----------

Hi Ravinder

I tried following code , my file nale is sample.xml

Code:
awk '/^<logentry revision=/{A=1} A{O=O?O ORS $0:$0} /<QC_ID><\/QC_ID>/{print O;B=1;next} B{print $0} /<\/logentry>/{B=0;O=""}' sample.xml

from the sample data i gave in the post it should display first record only

thanks
madan
# 9  
Old 04-03-2015
Hi Ravinder

it is giving entirees after QC_ID tag but not exactly from logentry start tag.

i need to get entire log entry from when QC_ID is null .

out put should be something like this

Code:
<logentry
   revision="21523">
<author>poord</author>
<date>2015-03-04</date>
<QC_ID> </QC_ID>
<Rally_ID> 42490 (Parent 42061)</Rally_ID> <Description> Async Health Check: History Count </Description> 
<Deployment_Change_Needed> No</Deployment_Change_Needed> <Deployment_Change_Description> No</Deployment_Change_Description>
</logentry>

# 10  
Old 04-06-2015
Hi Ravinder my input file is attached , please have a look .

thanks in advance.
# 11  
Old 04-06-2015
The proposal in post#5 works out of the box!
This User Gave Thanks to RudiC For This Post:
# 12  
Old 04-06-2015
Generalised version of RudiC's suggestion:
Code:
awk '/<logentry revision/{print x}1' file | awk -v key=QC_ID -v val="" '$0~"<" key ">" val "<"' RS=

This User Gave Thanks to Scrutinizer For This Post:
# 13  
Old 04-07-2015
I would like to thank Rudi and Ravinder you ppl made very easy . thank you for your help.

it was almost resolved .

---------- Post updated at 10:16 AM ---------- Previous update was at 10:16 AM ----------

Smilie
Quote:
Originally Posted by Scrutinizer
Generalised version of RudiC's suggestion:
Code:
awk '/<logentry revision/{print x}1' file | awk -v key=QC_ID -v val="" '$0~"<" key ">" val "<"' RS=

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract Matched Records from XML

Hi All, I have a requirement to extract para in XML file on the basis of another list file having specific parameters. I will extract these para from XML and import in one scheduler tool. file2 <FOLDER DATACENTER="ControlMserver" VERSION="800" PLATFORM="UNIX" FOLDER_NAME="SH_AP_INT_B01"... (3 Replies)
Discussion started by: looney
3 Replies

2. Shell Programming and Scripting

Extract top 20 records from sybase db in shell script

Hi, I am new to advanced scripting. I need to get top 20 records from database (Sybase) with a condition that all Char/varchar columns should have more than 4 characters. I need to do this via shell scripting, I have got half logic (on how to get varchar/char columns and stored it in a... (2 Replies)
Discussion started by: Selva_2507
2 Replies

3. Shell Programming and Scripting

How to Parse the XML data along with the URL in Shell Script?

Hi, Can anybody help to solve this. I want to parse some xmldata along with the URL in the Shell. I'm calling the URL via the curl command Given below is my shell script file export... (7 Replies)
Discussion started by: Megala
7 Replies

4. Shell Programming and Scripting

Extract and parse XML data (statistic value) to csv

Hi All, I need to parse some statistic data from the "measInfo" -eg. 25250000 (as highlighted) and return the result into line by line, and erasing all other unnecessary info/tag. Thought of starting with grep "measInfoID="25250000" but this only returns 1 line. How do I get all the output... (8 Replies)
Discussion started by: jackma
8 Replies

5. Shell Programming and Scripting

Shell script (not Perl) to parse xml with awk

Hi, I have to make an script according to these: - I have couples of files like: xxxxxxxxxxxxx.csv xxxxxxxxxxxxx_desc.xml - every xml file has diferent fields, but keeps this format: ........ <defaultName>2011-02-25T16:43:43.582Z</defaultName> ........... (2 Replies)
Discussion started by: Pluff
2 Replies

6. Shell Programming and Scripting

extract xml tag based on condition

Hi All, I have a large xml file of invoices. The file looks like below: <INVOICES> <INVOICE> <NAME>Customer A</NAME> <INVOICE_NO>1234</INVOICE_NO> </INVOICE> <INVOICE> <NAME>Customer A</NAME> <INVOICE_NO>2345</INVOICE_NO> </INVOICE> <INVOICE> <NAME>Customer A</NAME>... (9 Replies)
Discussion started by: angshuman
9 Replies

7. Shell Programming and Scripting

Parse XML file in shell script

Hi Everybody, I have an XML file containing some data and i want to extract it, but the specific issue in my file is that the data is repeated some times like the following example : <section1> <subsection1> X=... Y=... Z=... <\subsection1> <subsection2> X=... Y=... Z=...... (2 Replies)
Discussion started by: yassine
2 Replies

8. Shell Programming and Scripting

regex/shell script to Parse through XML Records

Hi All, I have been working on something that doesn't seem to have a clear regex solution and I just wanted to run it by everyone to see if I could get some insight into the method of solving this problem. I have a flat text file that contains billing records for users, however the records... (5 Replies)
Discussion started by: Jerrad
5 Replies

9. Shell Programming and Scripting

Help with shell script to extract data from XML file

Hello Scripting Gurus, I need help with extracting data from the XML file using shell script. The data is in a large XML and I need to extract the id values of all completedworkflows. Here is a sample of it. Input and output data is also in the attached text files. <wfregistry>... (5 Replies)
Discussion started by: yajaykumar
5 Replies

10. Shell Programming and Scripting

Parse a string in XML file using shell script

Hi! I'm just new here and don't know much about shell scripting. I just want to ask for help in creating a shell script that will parse a string or value of the status in the xml file. Please sample xml file below. Can you please help me create a simple script to get the value of status? Also it... (46 Replies)
Discussion started by: ayhanne
46 Replies
Login or Register to Ask a Question