The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to extract text from a line in file findprakash UNIX for Dummies Questions & Answers 7 12-22-2008 07:19 PM
Extract pattern from text line TehOne Shell Programming and Scripting 3 10-15-2008 01:46 PM
Extract pattern from text line vampirodolce Shell Programming and Scripting 9 10-14-2008 12:17 PM
awk: need to extract a line before a pattern npn35 Shell Programming and Scripting 17 06-29-2008 11:38 PM
extract a particular start and end pattern from a line manish205 Shell Programming and Scripting 7 02-07-2008 06:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-24-2008
TehOne TehOne is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 55
Question Extract pattern from text line

The text line has the following formats:

what.ever.bla.bla.C01G06.BLA.BLA2
what.ever.bla.bla.C11G33.BLA.BLA2
what.ever.bla.bla.01x03.BLA.BLA2
what.ever.bla.bla.03x05.BLA.BLA2
what.ever.bla.bla.Part01.BLA.BLA2

and other similar ones, I need a way to select the "what.ever.bla.bla" part out of the text.

So basically it has to be based on such regex:


Code:
(.*?)(C[0-9]+G[0-9]+|[0-9]+x[0-9]+|Part[0-9]+)

where (.*?) is the part I want to extract... any ideas?
  #2 (permalink)  
Old 12-25-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
Sorry, its not clear to me.

Do you want to extract the first or the second part?

what.ever.bla.bla - no need to extract this as its a constant

C01G06.BLA.BLA2 - for this just strip off the above pattern
  #3 (permalink)  
Old 12-25-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,089

Code:
sed 's/\(.*\)\(C[0-9][0-9]*G[0-9][0-9]*\)\(.*\)/\1/'

  #4 (permalink)  
Old 12-25-2008
TehOne TehOne is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 55
Quote:
Originally Posted by summer_cherry View Post
Code:
sed 's/\(.*\)\(C[0-9][0-9]*G[0-9][0-9]*\)\(.*\)/\1/'
That's perfect, thanks!
  #5 (permalink)  
Old 12-25-2008
TehOne TehOne is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 55
Quote:
Originally Posted by matrixmadhan View Post
Sorry, its not clear to me.

Do you want to extract the first or the second part?

what.ever.bla.bla - no need to extract this as its a constant

C01G06.BLA.BLA2 - for this just strip off the above pattern
The what.ever.bla.bla was just an example, it does differ.
It can be Example1.C11G33 or Bla123.Bla123.C11G33 and so on,
I need to extract always the name that is befor the "C11G33" no matter what it is .*?

The only thing that stays is the C11G33 or 01x03 or Part01 just with different numbers, just look on my regex example again.
Closed Thread

Bookmarks

Tags
sed regex

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0