the care and feeding of fgrep

Randal Schwartz merlyn at iwarp.intel.com
Wed Nov 29 07:21:29 AEST 1989


In article <453 at nixba.UUCP>, mike at nixba (Mike Lyons) writes:
| This is something that bugs me now and then (before I forget it again :-)...
| 
| The man page for the grep family has the following description for fgrep:
| 
| 		fgrep [ options ] [ strings ] [ files ]
| 
| The man page also states "Fgrep patterns are fixed strings; it is fast and 
| compact"  My question is, how the heck do you give a list of strings (as im-
| plied here) as an arg to fgrep? Every combination of quotes that I've come up 
| with always results in fgrep treating all but the first string in a list as a 
| filename, with the accompanying "can't open" complaints.  
| 
| When I use fgrep, I invariably put the strings into a file and use the -f 
| option, but this *really shouldn't* be necessary if the man page is correct.  
| 
| Please enlighten me :-)

A Zen master will whack you on the side of your head with his stick at
that request, but I'll try to be a "kinder, gentler" response.

The string arg to fgrep needs *newline*-separated strings, ala:

$ fgrep 'root
sys
merlyn' /etc/passwd
... [output appears here] ...
$

If you use the non-syntactically-powerful C-shell, you'll have to
escape each newline with a backslash, as in:

% fgrep 'root\
sys\
merlyn' /etc/passwd
... [output appears here] ...
%

There.

[look ma... no Perl program... :-]

Just another UNIX hacker,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/



More information about the Comp.unix.questions mailing list