Have you heard this old saw:
UNIX beginners use
because it's all they know about.
Intermediate users use
because the manual says it's
Advanced users use
because they've tried it.
Yes, despite what the manual page says (or rather, used to say, because
manual pages have been rewritten to
acknowledge the fact),
is usually the slowest of the
[I believe that
stands for "fixed
because it doesn't accept metacharacters.
If you want to prove this to yourself, try using the
program (shown in article
to give you the average execution time of a search.
Here's the result of my
search for the string
in a large directory crowded with
saved mail files.
runtime -10 grep Waldo *
4.13u 0.83s 0:04 0+203k 21+0io 19pf+0w
runtime -10 fgrep Waldo *
5.19u 0.80s 0:05 0+195k 4+0io 2pf+0w
runtime -10 egrep Waldo *
2.61u 0.76s 0:02 0+244k 0+0io 0pf+0w
On my SPARCstation IPC,
managed the search in four seconds,
in five, and
in only two.
the least CPU time.
Just for the heck of it, let's see how some other search programs
can also emulate the
runtime -10 sed -n '/Waldo/p' *
3.64u 1.20s 0:04 0+227k 2+0io 1pf+0w
runtime -10 awk '/Waldo/' *
4.86u 0.76s 0:05 0+279k 1+0io 0pf+0w
runtime -10 perl -ne \'print if \(/Waldo/\) \; \' *
2.94u 0.69s 0:03 0+498k 28+4io 27pf+0w
(Note that we have to escape any characters that the shell might
interpret in the
is faster than all but
, but even
edges your basic
by a hair.
is by far the slowest - it even lost to
This doesn't mean that
is useless, though.
It has a
couple of handy options:
requires a line to be exactly the same as the search pattern;
takes one or many search patterns from a file.
You can sometimes exploit the fact that
regular expressions, and so using it to search for literal asterisks
or other regular expression metacharacters can save you a bit of
The time saved on the command line can be worth the slower