How do I extract the third field in an xml entry?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I extract the third field in an xml entry?
# 1  
Old 05-11-2012
How do I extract the third field in an xml entry?

I have the following XML entry - I need to extract the contents of the third defined variable, Asset_Name.

Code:
<AMS Asset_Class="package" Asset_ID="XXXXXXXXXXXXXXXXXXXX" Asset_Name="MOVIE_XXXXXXXXXXX_XXXXXXXX" Creation_Date="2011-09-13" Description="test asset package" Product="MOD" Provider="XXXXXXXX" Provider_ID="XXXXXX.XXX" Verb="" Version_Major="1" Version_Minor="0" />

I need to get a variable defined with the contents of Asset_Name. How do I pull this out? Awk? What would that look like? Much thanks for any help.

Last edited by Scrutinizer; 05-11-2012 at 03:22 PM.. Reason: code tags
# 2  
Old 05-11-2012
Try:
Code:
perl -nle '/Asset_Name=("[^"]*")/;print $1' file.xml

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 05-11-2012
Thanks. Almost perfect - need that without the quotes. That spits back "MOVIE_XXXXXXXXXXX_XXXXXXXX". Need MOVIE_XXXXXXXXXXX_XXXXXXXX . Thanks again.
# 4  
Old 05-11-2012
Code:
perl -nle '/Asset_Name="([^"]*)"/;print $1' file.xml

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 05-11-2012
Worked perfectly. Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

2. Programming

Field delimited data to XML

Hi, We need to produce a XML file based on a record/field delimited data file. At this point we could just script something out but I would like to ask the community what would be the best choice of programming language to do this, in terms of performance of execution, and in terms of complexity... (9 Replies)
Discussion started by: Indalecio
9 Replies

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

4. Red Hat

How to get a particular field from xml file?

i have a xml file and in that input file path is given. how to fetch that input file path using shell script. (4 Replies)
Discussion started by: ramsavi
4 Replies

5. Shell Programming and Scripting

Extract Multivalue from XML

I have below attached xml file , how can I have my desired output as below. i/p file <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:executeMDXResponse... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

6. Shell Programming and Scripting

Extract value from XML

I have a file like below <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:executeMDXResponse... (9 Replies)
Discussion started by: manas_ranjan
9 Replies

7. Shell Programming and Scripting

How to get a field from an XML?

We have an input XML of the following form <item> <account>1234</account> <id>345</id> </item> How do we get the value of <account> tag (1234) using UNIX ? (6 Replies)
Discussion started by: Jassz
6 Replies

8. UNIX for Dummies Questions & Answers

Extract Field Value from XML file

Hi, Within a UNIX shell script I need to extract a value from an XML field. The field will contain different values but will always be 6 digits in length. E.g.: <provider-id>999999</provider-id> I've tried various ways but no luck. Any ideas how I might get the provider id (in this case... (2 Replies)
Discussion started by: pnclayt11
2 Replies

9. Shell Programming and Scripting

Help needed XML Field Extraction

I had an immediate work to sort out the error code and error message which are associated within the log. But here im facing an problem to extract 3 different fields from the XML log can some one please help. I tried using different script including awk & nawk, but not getting the desired output. ... (18 Replies)
Discussion started by: raghunsi
18 Replies

10. Shell Programming and Scripting

Extract xml data

Hi all, I have the following xml file : <xmlhead><xmlelement1>element1value</xmlelement1>\0a<xmlelement2>jjasd</xmlelement2>...</xmlhead> As you can see there are no lines or spaces seperating the elements, just the character \0a. How can i find and print the values of a specific element?... (1 Reply)
Discussion started by: nthed
1 Replies
Login or Register to Ask a Question