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

Notices


Reply
  Search this Thread
Old 08-18-2011, 03:01 AM   #1
rya11111
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Rep: Reputation: Disabled
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!
 
Old 08-18-2011, 03:22 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
We can't help you if you don't explain your issue completely? what language are you doing this in etc.?
 
Old 08-18-2011, 04:45 AM   #3
rya11111
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
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!
 
Old 08-18-2011, 04:58 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Grep is the wrong choice here. I would suggest awk or sed. As an example:
Code:
awk -F"[><]" '$2 == "filename"{print $3}' file
 
Old 08-18-2011, 05:06 AM   #5
rya11111
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
thanks!

That definitely solved this problem! thanks a lot!
 
Old 08-18-2011, 05:19 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
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.
 
Old 08-18-2011, 05:43 AM   #7
rya11111
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
xml2

Quote:
Originally Posted by acid_kewpie View Post
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!
 
Old 08-18-2011, 06:01 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
really? it just makes basic XML really easy to grep and cut. Doddle I thought.
 
Old 08-18-2011, 06:06 AM   #9
rya11111
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
xml2

Quote:
Originally Posted by acid_kewpie View Post
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..
 
Old 08-18-2011, 06:09 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
well if you've only got that ONE thign to do then you've done it already!
 
Old 08-18-2011, 06:14 AM   #11
rya11111
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
xml2

Quote:
Originally Posted by acid_kewpie View Post
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!!!
 
  


Reply


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
[Grep,Awk,Sed]Parsing text between XML tags. ////// Programming 5 07-26-2011 12:54 PM
[SOLVED] Is *libqt4-xml* equivalent of *libxml2* with respect to *XML* parsing ? TheIndependentAquarius Linux - Software 1 11-25-2010 08:34 PM
no xml, convert tvtime stationlist to xml for mythtv/freevo... frenchn00b Linux - General 8 11-04-2007 12:35 AM
LXer: StAX’ing up XML: Streaming API for XML LXer Syndicated Linux News 0 11-30-2006 08:54 AM
configure: error: could not find DocBook XML DTD V4.1.2 in XML catalog Fadoksi Linux - Software 1 07-16-2006 07:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:48 AM.

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