LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-31-2011, 01:25 AM   #1
ameylimaye
LQ Newbie
 
Registered: Aug 2011
Posts: 25

Rep: Reputation: Disabled
Search from XML files??


hi,
i have an .xml file from which i have to grep some data.
can anyone tel me how do i do that.?

the xml file is something like this..

Code:
 <?xml version="1.0" encoding="UTF-8" ?> 
- <inventoryDataFile>
  <fileHeader /> 
- <LicenseInventoryData>
- <NetworkElement NeName="ABD001">
- <License ElsnId="ABD001" Fingerprint="843474_001037">
CapacityKey Id="CXC4020046">
  <Description>FAK1010002; Channel Element Down Link HW</Description> 
  <StartDate Day="15" Month="08" Year="2011" /> 
  <StopDate Day="31" Month="12" Year="9999" /> 
  <Capacity>256</Capacity> 
  <HardLimit>256</HardLimit> 
  </CapacityKey>
<CapacityKey Id="CXC4020009">
  <Description>FAK1010001; Channel Element Up Link HW A</Description> 
  <StartDate Day="15" Month="08" Year="2011" /> 
  <StopDate Day="31" Month="12" Year="9999" /> 
  <Capacity>256</Capacity> 
  <HardLimit>256</HardLimit> 
  </CapacityKey>
from this file i have to grep the highlighted text. Can anyone help me out?
Do you need more information?
 
Old 10-31-2011, 01:19 PM   #2
kakaka
Member
 
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
If I understand the structure of the XML file, you appear to need a context in which to determine which pieces of data you need to grab.

Also, almost any form of grep is generally for grabbing entire lines, but you appear to want pieces of lines.

I would suggest something like awk would be a better choice than grep, since awk can be used to navigate through the file maintaining an understanding of the context, unlike grep, and awk can easily grab pieces of lines.
 
Old 10-31-2011, 05:22 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,052

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
something like this:
Code:
egrep "(NetworkElement|Description|Capacity)"
?
 
Old 11-03-2011, 12:35 AM   #4
ameylimaye
LQ Newbie
 
Registered: Aug 2011
Posts: 25

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
something like this:
Code:
egrep "(NetworkElement|Description|Capacity)"
?
but with this syntax it will grad all the line in which these are present.! capacity is there in many lines.! so that is the problem.

can you help me out by using awk command?
 
Old 11-03-2011, 09:41 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,052

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
Quote:
Originally Posted by ameylimaye View Post
but with this syntax it will grad all the line in which these are present.! capacity is there in many lines.! so that is the problem.

can you help me out by using awk command?
maybe this will work better:
Code:
egrep "(NetworkElement|Description|\<Capacity\>)"
is this homework ?
 
  


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
Perl Search and Replace XML tags conditionally rammyp_1979 Programming 15 10-22-2010 10:11 AM
Need help to search pattern in xml file vishal_titre Programming 2 10-26-2008 10:24 AM
Need help to search pattern in xml file vishal_titre Programming 6 10-24-2008 03:07 PM
PHP-XML Search Engine Boby Programming 1 04-25-2005 05:34 AM


All times are GMT -5. The time now is 04:23 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