Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grep question: either of 2 patterns?



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




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org