The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Regular expression Help Harikrishna Shell Programming and Scripting 3 06-11-2008 08:20 AM
regular expression help pls miwinter UNIX for Dummies Questions & Answers 3 06-05-2008 01:14 AM
Regular expression maxvirrozeito UNIX for Dummies Questions & Answers 1 12-14-2007 08:02 AM
Need help in Regular Expression mahabunta UNIX for Dummies Questions & Answers 2 09-26-2006 05:11 PM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 10:59 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 04-03-2009
sickboy sickboy is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 62
Regular Expression Help

Hi there,

I have a line in a coded text from which the formtat is

Code:
DEF/AAA/AAA/AAA/AAA/AAA/AAA/AAA/AAA/AAA
where A equals a letter

but the fields after the DEF/ are optional. Which means the line could look like

Code:
DEF/AAA or
DEF/AAA/AAA etc etc
I am trying to a find regular expression that will find all those lines that begin with DEF/ and in the rest (up to 9 fields) there is one of the following codes (BCD or DFG).

Is it possible to make this is one regular expression or I should use "OR" and do sth like

Code:
DEF/(BCD|DFG)||DEF/.../(BCD|DFG) etc etc
Thanks!
  #2 (permalink)  
Old 04-03-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
doing an "and" search in plain grep - it is sometimes faster for a one-off bit of code to use pipes - tuning the regex can take a while

Code:
grep '^DEF' filename | grep -e BCD -e DFG
  #3 (permalink)  
Old 04-03-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
This should work with sed, awk or egrep:

Code:
DEF.*[BCD||DFG].*
Regards
  #4 (permalink)  
Old 04-03-2009
sickboy sickboy is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 62
Quote:
Originally Posted by Franklin52 View Post
This should work with sed, awk or egrep:

Code:
DEF.*[BCD||DFG].*
Regards
Works good! Thanks a lot! It matches regexp from tickle as well
  #5 (permalink)  
Old 04-03-2009
sickboy sickboy is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 62
Quote:
Originally Posted by sickboy View Post
Works good! Thanks a lot! It matches regexp from tickle as well
I was mistaken. It doesn't work. If there is not BCD or DFG in the line and the line starts with DEF/ it matches is as well.

Eg. I tried this
Code:
DEF/AAA/AAA/AAA/AAA/AAA/AAA
and the DEF.*[BCD||DFG].* recognizes it as it matches the regexp

How I can correct this??
  #6 (permalink)  
Old 04-04-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
This is what I get with egrep:

Code:
$ cat file
DEF/AAA/AAA/AAA/AAA
DEF/ABC/BCD/AAA/ABC
DEF/AAA/AAA/AAA/AAA
DEF/AAA/TTT/AAA/AAA
DEF/AAA/AAA/AAA/DFG
$ egrep 'DEF.*[BDC||DFG].*' file
DEF/ABC/BCD/AAA/ABC
DEF/AAA/AAA/AAA/DFG
$
Regards
  #7 (permalink)  
Old 04-03-2009
sickboy sickboy is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 62
Quote:
Originally Posted by jim mcnamara View Post
doing an "and" search in plain grep - it is sometimes faster for a one-off bit of code to use pipes - tuning the regex can take a while

Code:
grep '^DEF' filename | grep -e BCD -e DFG
Thanks for your answer but the problem is that I have to use the regular expression in an xml so I can't use grep.
Closed Thread

Bookmarks

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 07:04 AM.


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