Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-26-2013, 03:41 PM   #1
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">
<model>Brother HL-2270DW</model>

Thank you in advance for your assistance.

Last edited by n3wtux; 07-26-2013 at 03:47 PM.
Old 07-26-2013, 04:51 PM   #2
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


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 02:42 PM
[SOLVED] XML remove odd lines between tag grlopes Programming 9 09-16-2012 09:52 AM
how to add xml-stylesheet tag in a XML File using libxml2 ? peacemission Programming 6 05-26-2012 02:20 AM
Print xml tag only if lenght > 0 frambau Programming 5 02-13-2012 05:10 AM
How To get the data from a tag in XML File kingmaker2003 Programming 7 12-04-2008 11:12 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:47 AM.

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