Extract details from XML file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract details from XML file
# 1  
Old 07-29-2011
Extract details from XML file

Hi ,
I have one xml file contains more than 60 lines. I need to extract some details from the file and store it in new file.Not the whole file

Please find the xml file below:

<?xml version="1.0" encoding="UTF-8"?>
<DeploymentDescriptors xmlns="http://www.tibco.com/xmlns/dd">
<description>Rebuilt EAR for TRIO7.0.3 for defect fix 77677.</description>
<creationDate>7/18/11 11:27 AM</creationDate>

expected result:

Name: BillingRoutingServices
description: Rebuilt EAR for TRIO7.0.3 for defect fix 77677
Version: 12.0.2

Note: I need to append the next xml details in the same file.

Please help me on this ..
# 2  
Old 07-29-2011
Why are Name and Version capitalized but description not?
And I don't quite understand this: "I need to append the next xml details in the same file."

---------- Post updated at 06:34 PM ---------- Previous update was at 06:21 PM ----------

Try this:
perl -0777 -ne '
print "Name: $1\ndescription: $2\nVersion: $3\n" 
  while m|<name>(.*)</name>\n      
          <version>(.*)</version>|xg' INPUTFILE1 INPUTFILE2 INPUTFILE3 ...

Last edited by yazu; 07-29-2011 at 10:16 AM.. Reason: corrected wrong code
# 3  
Old 07-29-2011
nawk -F"[<|>]" ' $2~/name/ || $2~/description/ || $2~/version/ {printf ("%s : %s\n",$2,$3)}' test.xml

# 4  
Old 07-29-2011
Hi Yazu,
This is one example. I will get these details from one xml and keep it in one file. For the 2nd xml , i should do the same thing and append the new details in the same output file.

# 5  
Old 07-29-2011

Your code gives wrong output I believe.

This is output from your code
?xml version="1.0" encoding="UTF-8"? :
name : BillingRoutingServices
description : Rebuilt EAR for TRIO7.0.3 for defect fix 77677.
version : 12.0.2
name : {http://www.tibco.com/xmlns/repoinstance}RepoInstance

How about this?
awk '/^<name/ || /^<description/ || /^<version/{f=1;w++} w<=3&&f{f=0;print}' input_file

# 6  
Old 07-29-2011

I can use sed command to get the corresponding lines...

like this...
awk -F"[<|>]" ' $2~/name/ || $2~/description/ || $2~/version/ {printf ("%s : %s\n",$2,$3)}' TIBCO.xml > file.txt
sed -n '2,4p ' file.txt >> Details.txt

Now I need to append the same file "Details.txt" with new details.. How can i append ??

Thanks to all.....
# 7  
Old 07-29-2011
for file_name in `ls *.xml`
awk -F"[<|>]" ' $2~/name/ || $2~/description/ || $2~/version/ {printf ("%s : %s\n",$2,$3)}' "$file_name" > file.txt
sed -n '2,4p ' file.txt >> Details.txt

I assume , all the needed .xml files are in same directory here.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to extract jil file details in a excelsheet

I am very new to shell scripting. I have a autosys jil file that looks like :-- /* ------------- JOB1 ------------------ */ insert_job: JOB1 job_type: b owner: cm@pelonmuck permission: gx,ge,wx,we,mx,me date_conditions: 1 days_of_week: mo,tu,we,th,fr,su start_time: "18:30"... (9 Replies)
Discussion started by: newbie_shell
9 Replies

2. Shell Programming and Scripting

Extract a value from an xml file

I have this XML file format and all in one line: Fri Dec 23 00:14:52 2016 Logged Message:689|<?xml version="1.0" encoding="UTF-8"?><PORT_RESPONSE><HEADER><ORIGINATOR>XMG</ORIGINATOR><DESTINAT... (16 Replies)
Discussion started by: mrn6430
16 Replies

3. UNIX for Dummies Questions & Answers

Retrieving details from a tag of xml file

Hi, I want to retrieve details of a tag from xml file 1.xml <abc> abcdefgh ijklmn opq </abc> <xyz>sdfsdf sdfsdfsdfgg </xml> Required Output: abcdefgh ijklmn opq (1 Reply)
Discussion started by: rahulsk
1 Replies

4. Shell Programming and Scripting

Extract sentence and its details from a text file based on another file of sentences

Hi I have two text files. The first file is TEXTFILEONE.txt as given below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (7 Replies)
Discussion started by: my_Perl
7 Replies

5. Shell Programming and Scripting

Extract a particular xml only from an xml jar file

Hi..need help on how to extract a particular xml file only from an xml jar file... thanks! (2 Replies)
Discussion started by: qwerty000
2 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

extract a pattern from a xml file

Hello All, I want to write a shell script for extracting a content from a xml file the xml file looks like this: <Variable name="moreAxleInfo"> <type> <Table> <type> <NamedType> <type> <TypeRef... (11 Replies)
Discussion started by: suvendu4urs
11 Replies

8. Shell Programming and Scripting

Extract XML content from a file

310439 2012-01-11 03:44:42,291 INFO PutServlet:? - Content of the Message is:="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED> 310440 <BATCH_ID>12345678519</BATCH_ID> 310441 <UID>3498748823</UID> 310442 <FEED_TYPE>FULL</FEED_TYPE> 310443 <MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME> 310444... (11 Replies)
Discussion started by: arukuku
11 Replies

9. Shell Programming and Scripting

i want to extract details for particular file

Hi i have following file uuid ( RO) : 62701790-60da-dd9a-669d-a563aac1c435 host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed sr-uuid ( RO): 62103d07-e0aa-acf3-2d9f-414ad3377bd0 device-config (MRO): location: /dev/xapi/block ... (6 Replies)
Discussion started by: bp_vardhaman
6 Replies

10. Shell Programming and Scripting

How to extract text from xml file

I have some xml files that got created by exporting a website from RedDot. I would like to extract the cost, course number, description, and meeting information. <?xml version="1.0" encoding="UTF-16" standalone="yes" ?> - <PAG PAG0="3AE6FCFD86D34896A82FCA3B7B76FF90" PAG3="525312"... (3 Replies)
Discussion started by: chrisf
3 Replies
Login or Register to Ask a Question