grep infix operator - Ubuntu

This is a discussion on grep infix operator - Ubuntu ; the man page for grep indicates that the verical bar is the infix operator and "grep grey|gray would show either grey or gray. It does not work here. It returns the error "operator gray unknown". Would some kind person post ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: grep infix operator

  1. grep infix operator

    the man page for grep indicates that the verical bar
    is the infix operator and "grep grey|gray would show
    either grey or gray. It does not work here. It returns
    the error "operator gray unknown".

    Would some kind person post an example that works?
    Thanks,
    Charles

  2. Re: grep infix operator

    charles cashion wrote:

    > the man page for grep indicates that the verical bar
    > is the infix operator and "grep grey|gray would show
    > either grey or gray. It does not work here. It returns
    > the error "operator gray unknown".
    >
    > Would some kind person post an example that works?
    > Thanks,
    > Charles


    ~$ echo -e "gray\ngreen\ngrey\nred" | grep -E 'grey|gray'
    gray
    grey

    ~$ echo -e "gray\ngreen\ngrey\nred" | grep -E grey|gray
    bash: gray: command not found

    ~$ echo -e "gray\ngreen\ngrey\nred" | egrep 'grey|gray'
    gray
    grey

    Notice you must enclose the vertical bar inside single quotes; this protects
    it from the shell. The shell interprets the bar as a pipe and attempts to
    pipe the output of 'grep grey' into a command 'gray'...not what we want.

    Also, note that the infix operator is part of the extended regular
    expression set and thus requires the '-E' option. Alternatively,
    use 'egrep' which is semantically equivalent to 'grep -E'.

    See "man 7 regex" for more information

    HTH,

    James
    --
    You are a fluke of the universe; you have no right to be here.


+ Reply to Thread