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]

What does grep stand for?



Doug Sweetser writes:
| This finally got me inspired enough to run grep --help.  I have been
| pestered by all those message - grep: Mail: Is a directory...
| Well there is a way to get it to be quiet about that,
| grep -d skip foo *, and a way to look through recursively,
| grep -d recurse foobar *.  Will alias those with dotfile (a utility to
| help manage shell or emacs .filerc's).

The best approach is to adopt the "unix  approach"  and  let  another
program  do the finding.  In particular, combining the "find" command
with "grep" is a unix cliche.  Try this:

find . -type f | xargs grep -i "foo.*bar"

This does a recursive search for all non-directories and  feeds  them
to  grep, which tells you which match the pattern.  You might want to
replace "foo.*bar" with some other  pattern  that  matches  something
that you know is there, to see how it works. Also, try "grep -il", to
get just the file names.

The "find" command is very powerful, but it has a command-line syntax
that  is  nearly  a  programming language in itself.  It's well worth
learning to use. When you combine find and grep as above, the results
make all other finders seem feeble by comparison.  But this is mostly
because a powerful finder inevitably has a complex syntax.

I have several variants of the above command line set up  as  aliases
or  one-line shell scripts.  I've seen a number of people who use the
alias:

alias f 'find . -type f | xargs grep'

I also use a script that I call "ge", which runs "grep  -il"  on  its
args  and  then  invokes  $EDITOR on the matching files.  It's really
handy when I want to find, say, all calls of a function.  The  script
is just:

if [ ! -n "$EDITOR" ];then EDITOR=vi; fi
P="$1"
shift
$EDITOR "+/$P/" `grep -il "$P" $*`

This script can be combined with find as above, of course,  once  you
understand what they both do.





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