grep question: either of 2 patterns?

Chris Devers cdevers at pobox.com
Tue Sep 2 12:00:20 EDT 2003


On Tue, 2 Sep 2003, dan moylan wrote:

> well,
>
>    grep -e "^(fee|fie)" junk.txt
>
> seems not to work, but this does:
>
>    grep -e "^\(fee\|fie\)" junk.txt
>
> dan

    % cat junk.txt
    fee
    fie
    foe
    fum

    % grep -e "^(fee|fie)" junk.txt
    % grep -E "^(fee|fie)" junk.txt
    fee
    fie

    % grep -e "^\(fee\|fie\)" junk.txt
    fee
    fie
    % grep -E "^\(fee\|fie\)" junk.txt

    % egrep "^\(fee\|fie\)" junk.txt
    % egrep "^(fee|fie)" junk.txt
    fee
    fie

So, -E works, -e works with backslashes, and egrep works as -E does.

This is relevant:

    % grep --help | grep -i '\-e'
      -E, --extended-regexp     PATTERN is an extended regular expression
      -e, --regexp=PATTERN      use PATTERN as a regular expression
    `egrep' means `grep -E'.  `fgrep' means `grep -F'.




-- 
Chris Devers cdevers at pobox.com
http://devers.homeip.net:8080/

MUM, n. [Acronym for Multi-Use Mnemonics.]
A meta-mnemonic methodology whereby one acronym references all the
features of a particular system.

    -- from _The Computer Contradictionary_, Stan Kelly-Bootle, 1995



More information about the Discuss mailing list