[comp.unix.questions] the care and feeding of fgrep

mike@nixba.UUCP (Mike Lyons) (11/24/89)

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 :-)

Peace,
  Mike
-- 
Michael D. Lyons / Nixdorf Computer AG / phone: +49 911 6415 609
Donaustrasse 36 :: D-8500 Nuernberg 60 :: Federal Republic of Germany
EUNET: mike@nixba.uucp   NERV: lyons.nue   OTHERWISE: ...unido!nixba!mike
I'd change the world for the better...if I could get my hands on the source code

andyb@coat.com (Andy Behrens) (11/25/89)

In article <453@nixba.UUCP> mike@nixba.UUCP (Mike Lyons) writes:
>  "Fgrep patterns are fixed strings."  My question is, how the heck do
>  you give a list of strings as an arg to fgrep?

You separate them with newlines.  The way you type the newlines depends
on which shell you are using.

	#! /bin/sh			#! /bin/csh

	fgrep 'string1			fgrep 'string1\
	string2				string2\
	string3' files			string3' files

(You can use "" instead of '' if you prefer).

--
Live justly, love gently, walk humbly.
					Andy Behrens
					andyb@coat.com

uucp:   {uunet,rutgers}!dartvax!coat.com!andyb
RFD 1, Box 116, East Thetford, Vt. 05043		(802) 649-1258
Burlington Coat, PO Box 729, Lebanon, N.H. 03766	(603) 448-5000

merlyn@iwarp.intel.com (Randal Schwartz) (11/29/89)

In article <453@nixba.UUCP>, mike@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@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/