grep

Matthew Miller mattdm at mattdm.org
Mon Jan 31 04:47:04 UTC 2005


On Sun, Jan 30, 2005 at 12:48:50PM -0600, Bill Gradwohl wrote:
> According to the grep man page:
> Grep understands two different versions of regular expression syntax:
> “basic” and “extended.” In GNU grep, there is no difference in 
> avail-
> able functionality using either syntax.
> 
> However, the following function differently:
> grep -G 'cat|dog|bird' filename (Basic)
> grep -E 'cat|dog|bird' filename (Extended)
> 
> Am I interpreting something incorrectly?

There's no difference in available functionality, but how you get to that
functionality differs -- in the "basic" case you'll have to use \| to make |
have a special meaning, and for "extended" you use the \ to *remove* the
special meaning.

> Does anyone know how to construct a regular expression or in any way get 
> a single grep execution to do an AND instead of an OR operation so that 
> it looks for more that one string and matches a line when ALL the items 
> exist on that line, and are possibly in RANDOM order?

Do you mind if it matches "cat cat cat", or most it be exactly all three? If
you need it to be each one exactly one time, it'll be much easier to just
invoke grep three times....

-- 
Matthew Miller            mattdm at mattdm.org        <http://www.mattdm.org/>
-->  Fedora Users & Developers Conference, hosted by Boston University  <--
February 18th, 2005                 <http://fedoraproject.org/wiki/FUDCon1>  




More information about the fedora-list mailing list