command file HELP

BALDWIN mike at whuxl.UUCP
Wed Feb 5 09:02:02 AEST 1986


> > find / -exec "fgrep this-is-the-string '{}' | awk -F: '{print $1}'" \;
> 
> find / -exec "fgrep this-is-the-string '{}' | awk '{print FILENAME}'" \;

Gak!  NEITHER of these has any chance of working!  The args to -exec
are passed to execvp(), so you can't just pass an arbitrary shell cmd
to it (this is on System V).  Also, {} is only substituted if it is a
*separate* arg.  If you want to put a pipeline into -exec with the
filename, you have to:

	find dir -exec /bin/sh -c 'prog1 $1 | prog2 $1' sh {} ';'

The $1 is used to pull in the {}, and the sh in front of {} is $0.
But ANYWAY, that still wouldn't fix it.  The $1 in the first one
will get substituted because it's in double quotes, and the FILENAME
in the second one will print "-", standard input.

Anybody ever heard of the -l option to *grep???  Try this:

	find / -type f -exec grep -l string {} ';'

Better yet, if you're on SV you can use xargs to bundle the files
up and save considerable amounts of time:

	find / -type f -print | xargs grep -l string

In the future, *please* give examples that at least
have a chance of working (i.e., try them once).
-- 
						Michael Baldwin
			(not the opinions of)	AT&T Bell Laboratories
						{at&t}!whuxl!mike



More information about the Comp.unix mailing list