LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-26-2013, 04:41 PM   #1
n3wtux
LQ Newbie
 
Registered: Feb 2010
Posts: 8

Rep: Reputation: 0
Trying to parse a value from XML tag for a variable


I am trying to parse an xml doc to get the asset_tag value to use as a variable. I only have sed installed on an extremely custom linux install. This should be the only Printer device type in the doc. An earlier check will look to see if there is more than one or a null value for this section. There are multiple "device type" tags with asset_tag values. How would you use the aforementioned sed to get that value?

<device type="Printer">
<asset_tag>001BA9BECE16</asset_tag>
<ip_address>10.10.10.10</ip_address>
<role>Report</role>
<model>Brother HL-2270DW</model>
</device>

Thank you in advance for your assistance.

Last edited by n3wtux; 07-26-2013 at 04:47 PM.
 
Old 07-26-2013, 05:51 PM   #2
n3wtux
LQ Newbie
 
Registered: Feb 2010
Posts: 8

Original Poster
Rep: Reputation: 0
I found a solution to this issue, thanks to a co-worker.

cat file.xml |sed -n '/Printer/,+5p'| sed -n '/<asset_tag>/p'|sed -n 's/\s*\t*<asset_tag>//p'|sed -n 's/<.*$//p'

Thank you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to search for a corresponding tag in xml file and replace the corresponding value userofunix Linux - Newbie 1 09-17-2012 03:42 PM
[SOLVED] XML remove odd lines between tag grlopes Programming 9 09-16-2012 10:52 AM
how to add xml-stylesheet tag in a XML File using libxml2 ? peacemission Programming 6 05-26-2012 03:20 AM
Print xml tag only if lenght > 0 frambau Programming 5 02-13-2012 06:10 AM
How To get the data from a tag in XML File kingmaker2003 Programming 7 12-05-2008 12:12 AM


All times are GMT -5. The time now is 05:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration