RE's and grep

Derek Martin invalid at pizzashack.org
Tue Sep 2 15:35:49 EDT 2003


On Tue, Sep 02, 2003 at 12:43:09PM -0500, karina.popkova at verizon.net wrote:
> Now, what I really want to do
> is to search for general words
> that have a pattern, but also to 
> exclude a specific vowel or consonant.
> I.E., to make as a part of the search pattern
> that you call an RE, to look for given words
> and make sure that the vowel "a" or the
> vowel "e" is not a part of the word or string?

If you're searching prose, and you want to match a pattern in a WORD,
and at the same time ensure the same word doesn't contain the
specified vowel, that can get complicated.  Remember that grep matches
patterns contained in a LINE, not per-word.

If your words are one per line, this is much easier.  You can do it
with a simple pipe, like this:

  $ grep <pattern> <file> | grep -v 'a'

Or, if you wanted to make sure ALL of those vowels weren't contained
in the word, 

  $ grep <pattern> <file> | grep -v '[aei]'

> How could you find all words in a file that do not
> have the letter: a, or e or i, and so on (???)

Again, they'd need to be one word per line, but this would suffice:

  $ grep -v '[a]' file

Just add whatever characters you want to eliminate in the brackets.

> Or do not have the letters a, and e, and i in the same word?

If the file contains more than one word per line (such as a dictionary
with definitions), this won't work.  It can still be done, but you'd
need a lot more logic.  AFAIK, there's no way to do that with a single
regular expression, or even a simple pipeline.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.
Replying to it will result in undeliverable mail.
Sorry for the inconvenience.  Thank the spammers.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.blu.org/pipermail/discuss/attachments/20030902/82f8b66c/attachment.sig>


More information about the Discuss mailing list