LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 12: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, 12:19 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
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, 04:22 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
something like this:
Code:
egrep "(NetworkElement|Description|Capacity)"
?
 
Old 11-02-2011, 11:35 PM   #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, 08:41 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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



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 09:11 AM
Need help to search pattern in xml file vishal_titre Programming 2 10-26-2008 09:24 AM
Need help to search pattern in xml file vishal_titre Programming 6 10-24-2008 02:07 PM
PHP-XML Search Engine Boby Programming 1 04-25-2005 04:34 AM

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

All times are GMT -5. The time now is 12:14 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
Open Source Consulting | Domain Registration