The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep problem yogesh_powar Shell Programming and Scripting 2 11-09-2006 03:43 PM
grep problem asal_email2 UNIX for Dummies Questions & Answers 4 06-22-2005 05:49 PM
problem with grep vivekshankar UNIX for Dummies Questions & Answers 7 05-25-2005 10:49 AM
grep problem svennie UNIX for Dummies Questions & Answers 5 11-08-2004 01:29 AM
grep problem xiamin UNIX for Dummies Questions & Answers 4 09-06-2001 06:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-23-2008
Registered User
 

Join Date: Jun 2008
Posts: 29
grep and cut problem

Hello folks,
I have to (e)grep out a certain pattern e.g. <TAG1> from a huge log file which does not have any space as such.
The thing is that once I have 'grep'ed out the <TAG1> from the file I need to extract the content within the tags, i.e,
<TAG1>Data_To_Be_Extracted</TAG1>
The underlined data needs to be extracted.
The problem is that with such a huge file with big wide lines with lots of tags I can't get hold of any delimiter.
Thanks in advance.
Reply With Quote
Forum Sponsor
  #2  
Old 07-23-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,031
Code:
sed 's/.*<TAG1>\([^>]*\)<\/TAG1>.*/\1/g'
Reply With Quote
  #3  
Old 07-23-2008
Registered User
 

Join Date: Jun 2008
Posts: 29
I am sorry Zaxxon but wont this be just replacing the stuff? Please forgive my incompetence with sed. Is there any subString sort of functionality in UNIX?
Reply With Quote
  #4  
Old 07-23-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 983
Question Can you provide a sample of the file?

It can often be easier to understand when we see actual data, as opposed to answering a theoretical question.
Reply With Quote
  #5  
Old 07-23-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,031
Nodding to joeyg, I can say that the sed code was working with your example, see yourself:

Code:
root@isau02:/data/tmp/testfeld> cat infile2
somelala.awno2irbn8sp+0<TAG1>Data_To_Be_Extracted</TAG1>some more data or is it rubbish or blaapowjdaowih2
xawmwduhawudhguvsiu31ell.wor8sp+0<TAG1>Data_To_Be_Extracted</TAG1>jscb akjbfq23jrbfhhhh3
aukwdhaiubf23__fgv<TAG1>Data_To_Be_Extracted</TAG1>e mot ri t ubs rjsa 3221u3r
root@isau02:/data/tmp/testfeld> sed 's/.*<TAG1>\([^>]*\)<\/TAG1>.*/\1/g' infile2
Data_To_Be_Extracted
Data_To_Be_Extracted
Data_To_Be_Extracted
root@isau02.debeka.de:/data/tmp/testfeld>
I thought that is what you wanted. You got the stuff between those two tags. It's not touching the input file, if you mean that.
Reply With Quote
  #6  
Old 07-23-2008
Registered User
 

Join Date: Jun 2008
Posts: 29
Thanks a lot Zaxxon ... it is running fine when I am hard coding the file name but if I am putting the file name like:
sed 's/.*<TAG1>\([^>]*\)<\/TAG1>.*/\1/g' $fileName it is returning the entire file.
Note: There are multiple occurences of <TAG1>.

Last edited by Rajat; 07-23-2008 at 09:41 AM.
Reply With Quote
  #7  
Old 07-23-2008
Registered User
 

Join Date: Jun 2008
Posts: 29
i guess it's just working with just one particular file for some weird reason ... any suggestions people?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0