LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trying to parse a value from XML tag for a variable (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-parse-a-value-from-xml-tag-for-a-variable-4175471054/)

n3wtux 07-26-2013 03:41 PM

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.

n3wtux 07-26-2013 04:51 PM

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


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