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 ">
<name>BillingRoutingServices</name>
<description>Rebuilt EAR for TRIO7.0.3 for defect fix 77677.</description>
<version>12.0.2</version>
<owner>EAI</owner>
<creationDate>7/18/11 11:27 AM</creationDate>
<isApplicationArchive>true</isApplicationArchive>
<DeploymentDescriptorFactory>
<name>{http://www.tibco.com/xmlns/repoinstance\ }RepoInstance</name>
<deploymentDescriptorFactoryClassName>com.tibco.dd.repo.RepoInstance</deploymentDescriptorFactoryClassName>
<deploymentDescriptorXsdFileName>com/tibco/dd/repo/RepoInstance.xsd</deploymentDescriptorXsdFileName>
</DeploymentDescriptorFactory>
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 ..
Thanks
Chells......
yazu
July 29, 2011, 7:34am
2
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
<description>(.*)</description>\n
<version>(.*)</version>|xg' INPUTFILE1 INPUTFILE2 INPUTFILE3 ...
nawk -F"[<|>]" ' $2~/name/ || $2~/description/ || $2~/version/ {printf ("%s : %s\n",$2,$3)}' test.xml
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.
Thanks..
panyam
July 29, 2011, 8:11am
5
@itkamraj ,
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
@panyam ,
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.....
panyam
July 29, 2011, 9:01am
7
for file_name in `ls *.xml`
do
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
done
I assume , all the needed .xml files are in same directory here.