tobold.org

correct • elegant • free

△ comp.unix.shell △

◅ remote login via shell script

timer script ▻

A bit of a grep stumper

In article <381fd510@newsserver1.picknowl.com.au>,
Mediocrates  <Mediocrates@don'tbother.spammingme> wrote:
>Here's what I'm trying to do: grep for either a or b. According to info
>and man I need to use the infix operater '|' .

Such things are usually discussed on comp.unix.shell: followups there.

>                                               However, doing a "grep
>a|b" obviously won't work due to linux interpreting it as a pipe
>operation

It's your shell that interprets it as the pipeline operator; you just
need to put quote marks around it.

>          and "\|" means to look for a "|". Does anyone know how to get
>it to work?

Traditionally, only egrep supports alternation.

    egrep 'a|b' /etc/group

With the GNU grep utilities, you have a bewildering choice.  You can
use `egrep', as above; you can use `grep -E', which makes `grep' behave
almost like `egrep'; or you can backwhack the alternation operator.

    grep -E 'a|b' /etc/group
    grep 'a\|b' /etc/group

Tim.
--
Tim Goodwin   | "People think [ W. Gibson is ] hi-tech because his prose
Leicester, UK | is as pleasant to read as a C++ program." -- JT

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: gnu.misc.discuss,comp.unix.shell
Subject: Re: A bit of a grep stumper
Followup-To: comp.unix.shell
Date: 3 Nov 1999 10:20:10 -0000
Organization: University of Leicester, UK
Message-ID: <7vp29g$8qo$1@ltpcg.star.le.ac.uk>
References: <381fd510@newsserver1.picknowl.com.au>

△ comp.unix.shell △

◅ remote login via shell script

timer script ▻