Basic Grep Question

Dotan Cohen dotancohen at gmail.com
Tue Mar 13 20:04:00 UTC 2007


On 13/03/07, Marc Schwartz <marc_schwartz at comcast.net> wrote:
> Dan Track wrote:
> > Hi
> >
> > Could someone please tell me how I can grep for two or more different
> > words in one command instead of piping them through.
> >
> > e.g I don't want to do
> >
> > cat /tmp/file | grep -v cat | grep -v grey
> >
> > I'd like to run that from one grep command.
> >
> > Many Thanks
> > Dan
>
> Two possibilities:
>
> $ cat .Xresources
> Emacs.default.attributeBackground:      white
> Emacs.default.attributeForeground:      black
> !
> XEmacs*EmacsFrame.default.attributeForeground: black
> XEmacs*EmacsFrame.default.attributeBackground: white
> !
> xterm*geometry: 100x32
> xterm*faceName: bitstream vera sans mono
> xterm*faceSize: 12
> xterm*background: white
> xterm*rightScrollBar: true
>
>
> # Use grep with the -E arg to specify extended
> # regex usage
>
> $ cat .Xresources | grep  -Ev "(white|black)"
> !
> !
> xterm*geometry: 100x32
> xterm*faceName: bitstream vera sans mono
> xterm*faceSize: 12
> xterm*rightScrollBar: true
>
>
> # Or just use egrep
>
> $ cat .Xresources | egrep  -v "(white|black)"
> !
> !
> xterm*geometry: 100x32
> xterm*faceName: bitstream vera sans mono
> xterm*faceSize: 12
> xterm*rightScrollBar: true
>
>
> You might want to look at:
>
>    http://en.wikipedia.org/wiki/Regular_expression
>    http://www.regular-expressions.info/
>
> There is also a great book:
>
>    http://regex.info/
>
> HTH,
>
> Marc Schwartz
>


>From Dan's question, it appears that he wants AND behaviour, not OR
behaviour, from the two greps.

Dotan Cohen

http://what-is-what.com/what_is/ubuntu.html
http://lyricslist.com/lyrics/lyrics/2/445/sepultura/against.html




More information about the fedora-list mailing list