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! |
We can't help you if you don't explain your issue completely? what language are you doing this in etc.?
|
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! |
Grep is the wrong choice here. I would suggest awk or sed. As an example:
Code:
awk -F"[><]" '$2 == "filename"{print $3}' file |
thanks!
That definitely solved this problem! thanks a lot!
|
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.
|
xml2
Quote:
|
really? it just makes basic XML really easy to grep and cut. Doddle I thought.
|
xml2
Quote:
|
well if you've only got that ONE thign to do then you've done it already!
|
xml2
Quote:
|
All times are GMT -5. The time now is 09:37 PM. |