[KLUG Members] grep, egrep, fgrep

Adam Tauno Williams members@kalamazoolinux.org
Thu, 06 May 2004 10:31:25 -0400


> Can anyone explain why there are still three different greps?

Because geeks are a ornery, contrary, and short-sighted lot?

> One of my associates says that they each were written for a purpose but
> supposedly their functionality should all be combined into just plain
> grep now.

And they would call that bgrep, for "bloated grep". :)  Sorry, just
getting warmed up for my .Net presentation on Tuesday.

But anyway, take a look....
[awilliam@estate2 awilliam]$ ls -l /bin/grep
-rwxr-xr-x  1 root root 77208 Jan  5 10:15 /bin/grep
[awilliam@estate2 awilliam]$ ls -l /bin/egrep
lrwxrwxrwx  1 root root 4 May  3 20:16 /bin/egrep -> grep
[awilliam@estate2 awilliam]$ ls -l /bin/fgrep
lrwxrwxrwx  1 root root 4 May  3 20:16 /bin/fgrep -> grep

And one grep it is.

> The reason I ask is I often need to search for filenames with a period
> in my pattern, like '.s' , for filenames like file.sam using a comand

ls | grep \\.s

> like (ls -1 | fgrep -e '.s') . The man pages say I should use -e '.s' to
> tell grep not to interpret the period. However only fgrep -e '.s' works
> as grep and egrep return anything with an s in it. Should I still be
> escaping the period somehow anyway?

Yep.

> I also can't seem to figure out how to search a file for lines
> containing either one thing or another in file order. Something like
> grep 'A or B' file.txt

-F, --fixed-strings
     Interpret PATTERN as a list of fixed strings, separated by  new-
     lines, any of which is to be matched.

[awilliam@estate2 Documents]$ cat file1
dude
[awilliam@estate2 Documents]$ cat file2
chic
[awilliam@estate2 Documents]$ grep --fixed-strings "`echo -e "dude
\nchic"`" file?
file1:dude
file2:chic