LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   XML grep (https://www.linuxquestions.org/questions/linux-newbie-8/xml-grep-897995/)

rya11111 08-18-2011 02:01 AM

XML grep
 
hi everyone, I am having trouble parsing the xml file to get the info between the tag ,
<filename>2010-08-14_hr-nagendra_horizons-in-modern.mp4</filename>

thanx for your help!

acid_kewpie 08-18-2011 02:22 AM

We can't help you if you don't explain your issue completely? what language are you doing this in etc.?

rya11111 08-18-2011 03:45 AM

ok, I have an xml file which is as below

<archive version="1.0">
<filename>2010-08-14_hr-nagendra_horizons-in-modern.mp4</filename>
<title>Horizons in modern medicines and yoga theraphy </title>
<presenter>Dr. H. R. Nagendra</presenter><description/><unit>NCast Telepresenter</unit>
<channel>FACULTY_send</channel>
<start>2010-08-14 04:33:45</start>
<duration>01:21:08</duration>
<timezone>-0700</timezone>
<width>1024</width>
<height>768</height>
<aspect_width>1024</aspect_width>
<aspect_height>768</aspect_height>
<main_window>0,0,1024,768</main_window><pip_window>716,537,256,192</pip_window><bitrate>1088</bitrate><framerate>25</framerate>
<file_format>mp4</file_format>
<video_format>h264</video_format>
<audio_format>aac</audio_format></archive>


now I want to get the text between the tags <filename></filename> using grep

I tried using: grep '^<filename>*' file.xml, but it gives me output as:
<filename>2010-08-14_hr-nagendra_horizons-in-modern.mp4</filename>
I don't want that tags to be displayed when using grep
soory for not providing this info earlier!

grail 08-18-2011 03:58 AM

Grep is the wrong choice here. I would suggest awk or sed. As an example:
Code:

awk -F"[><]" '$2 == "filename"{print $3}' file

rya11111 08-18-2011 04:06 AM

thanks!
 
That definitely solved this problem! thanks a lot!

acid_kewpie 08-18-2011 04:19 AM

Oddly I was looking at xml2 yesterday. that would take any xml and convert it into a much more parseable set of bash strings you can manipulate. just pipe the text into it and it spits it out the other end.

rya11111 08-18-2011 04:43 AM

xml2
 
Quote:

Originally Posted by acid_kewpie (Post 4446455)
Oddly I was looking at xml2 yesterday. that would take any xml and convert it into a much more parseable set of bash strings you can manipulate. just pipe the text into it and it spits it out the other end.

yeah .. i looked into it. I seems to make the tasks a lot easier but it seems complicated. dunno if a newbie like me will be able to harness it fully. thanks anyway!

acid_kewpie 08-18-2011 05:01 AM

really? it just makes basic XML really easy to grep and cut. Doddle I thought.

rya11111 08-18-2011 05:06 AM

xml2
 
Quote:

Originally Posted by acid_kewpie (Post 4446491)
really? it just makes basic XML really easy to grep and cut. Doddle I thought.

allright! I will follow ur advice and play with it for a while..

acid_kewpie 08-18-2011 05:09 AM

well if you've only got that ONE thign to do then you've done it already!

rya11111 08-18-2011 05:14 AM

xml2
 
Quote:

Originally Posted by acid_kewpie (Post 4446495)
well if you've only got that ONE thign to do then you've done it already!

I know but xml2 looks interesting... no harm in playing for a while!!!


All times are GMT -5. The time now is 09:37 PM.