It is currently Mon, 25 Sep 2023 10:27:43 GMT



 
Author Message
 grep problem
Hi,

I am using regular expressions in the grep command to get certain patterns
of a database containing a bunch of words.  The criteria is that I cannot
have the word "an" or "re" at the beginning or end of the word.  "an" or
"re" must be contained within the word.  For example: "candy", "drench", or
"meandering" are ok.  However, words like "another", "remark", "centre",
"median" are NOT ok ...

Any help will be great!

AV



 Tue, 18 Nov 2003 08:51:13 GMT   
 grep problem

egrep is your friend:

# (Assuming Posix Shell Syntax:
exclude='(an|re)'
egrep -v "((^$exclude)|($exclude$))"
--
Do NOT reply to the address given in the From: header. If you want to
reply by mail, use the following address (after deleting the XXX):
Ronald Otto Valentin Fischer <rovf...@thekeyboard.com>
(Tired of getting spam after posting a message? http://www.deadspam.com)



 Tue, 18 Nov 2003 14:09:41 GMT   
 grep problem

something like ^..*an..*$|^..*re..*$ comes to mind... not quite
sure. brain tired.

-Dan

--
This address expires.  Take out the hostname if your reply bounces.
Read http://dan.scream.org/pay4spam.html before you send ads to me.
This address may not be distributed unless this notice is included.
Visit http://dbirchall.epinions.com/user-dbirchall for my opinions.



 Wed, 19 Nov 2003 15:38:28 GMT   
 grep problem

That would allow some of the forbidden words like remark or another
since .* would also include spaces

Do you mean the input file has one word per line?
You didn't mention which grep (or platform) but if its gnu grep then
you may like the \B operator.

However if both situations occur on the same line your screwed,
without piping thru `grep -v' (sloppy).

If not gnu grep maybe something like:

       grep '[a-z]er[a-z]\|[a-z]an[a-z]'  
assuming no numbers are involved.
But again if both situations occur grep will include the line.



 Wed, 19 Nov 2003 23:40:19 GMT   
 
   [ 4 post ] 

Similar Threads

1. grep problem.

2. grep problems - strange

3. csh/grep problem (on Linux)

4. grep problem in ps aux

5. Q: Bizarre grep problem

6. sed/grep problems

7. 2K grep problem

8. grep problem


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software