Basic Grep Question

Cameron Simpson cs at zip.com.au
Tue Mar 13 22:11:52 UTC 2007


On 13Mar2007 15:42, Dan Track <dan.track at gmail.com> wrote:
| 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.

Various people have mentioned egrep's '(foo|bar)' notation.
Good for OR. For AND I start reaching for sed, since you
can write more logic. I have a script here:

  http://www.cskk.ezoshosting.com/cs/css/bin/grepall

that constructs a sed command to do AND, and runs it,
so (for the inverse of your example):

  grepall hairy grey cat < /tmp/file

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

My computer always does exactly what I tell it to do but sometimes I have
trouble finding out what it was that I told it to do.
        - Dick Wexelblat <rlw at ida.org>




More information about the fedora-list mailing list