System notes



grep

Version date: Thu May 24 14:28:12 EDT 2012

From corcoran Tue Jul 16 01:34:31 1991

Mike's Reader's Digest version of grep :
(don't forget man pages for more details)

definition: pattern matching search through a stream.

history: grep is an acronym derived from a search done in the
old ed/sed style editors. It stands for:
g)lobal
r)egular
e)xpression &
p)rint

usage & examples:
grep string filename - print all lines in filename containing string
grep -i string filename - as above but ignore case
grep -v string filename - print all lines that do NOT contain string

If filename is not given, input is taken from stdin. As in the example
ps ugax|grep pvendt
which will look for the pattern pvendt among all system processes. Try
that, then try "ps ugax|grep pvendt|grep -v grep" and see if you
understand what you observe.

Another useful tool is egrep (and fgrep) which allow more complex
pattern matching. egrep uses a C programming style flavor to describe
patterns. For example, to see all processes owned by you or Dale,
you could do this:
ps ugax|egrep 'pvendt|dcourte'
where | means OR in this context instead of PIPE.

Handy things to do using grep:
ypcat passwd | grep -i pat *** look through all NIS password file
entries for people named pat.
(ypcat may be lesson 4)
grep -i vendt /usr/lib/aliases *** see what mail aliases the system
has set up for you globally.
ypcat group|grep shollen *** see what groups Sheila belongs to

grep include *.c *** see what files are included
in a bunch of printserver source
files.
------------------------------------------------------------------
Note: This is a very brief introduction. Even at that this seems
quite long. I could probably go on an on! Apologies.
------------------------------------------------------------------


Please read The Standard Disclaimer regarding information found in these pages.

To return to the top of the Corcoran document archives Click Here

If you came here directly from a search engine, and would like to view these pages in the proper frames from the top, Start Here

Or start at the very top of Mike Corcoran's home page