LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to find and read out parms in an xml file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-and-read-out-parms-in-an-xml-file-613550/)

mcandy_123 01-14-2008 03:27 PM

how to find and read out parms in an xml file
 
hello !
I have for example following xml file content: <blabla>..<blabla/><blabla>..<blabla/><parm1>10</parm1><parm2>20<parm2/><blabla>..<blabla/><blabla>..<blabla/>
know I would like using grep or find or awk catch the parm 2 (20) by finding the value of parm 1 (10) first and displaying (print) parm 2 secondly.

Thanks in advance
br,
mcandy

Tinkster 01-14-2008 05:20 PM

Hi,

And welcome to LQ!

I'm not sure what the requirement is; is the name of the tag relevant at all,
or are you just looking for the first piece of VALUE after a value of 10?

[edit]
If my trivial assumption above was correct this simple sed below would do:

Code:


echo "<blabla>..<blabla/><blabla>..<blabla/><parm1>10</parm1><parm2>20<parm2/><blabla>..<blabla/><blabla>..<blabla/>"| sed -r 's/.+10<.+>([0-9]+).+/\1/g'
20

[/edit]


Cheers,
Tink

mcandy_123 01-15-2008 08:17 AM

Quote:

Originally Posted by Tinkster (Post 3022460)
Hi,

And welcome to LQ!

I'm not sure what the requirement is; is the name of the tag relevant at all,
or are you just looking for the first piece of VALUE after a value of 10?

[edit]
If my trivial assumption above was correct this simple sed below would do:

Code:


echo "<blabla>..<blabla/><blabla>..<blabla/><parm1>10</parm1><parm2>20<parm2/><blabla>..<blabla/><blabla>..<blabla/>"| sed -r 's/.+10<.+>([0-9]+).+/\1/g'
20

[/edit]


Cheers,
Tink

Hi, Tink !
First of all, thanks for the reply !
my string looks like following:
long part befor in this string...<dscpService>0</dscpService><Enable>1</Enable>...long part afterwards
So, I should find first the tag <dscpService>0</dscpService> , which is uniq in this xml file and direct afterwards comes the Enable Flag which could be 0=off or 1=on. So I need to read the Enable flag or to define it in a parm.

hope thats a better description,
br,
mcandy


All times are GMT -5. The time now is 08:10 AM.