recursive grep

Bennett Todd bet at orion.mc.duke.edu
Tue Sep 12 12:59:22 AEST 1989


The original poster asked for a straightforward construct to let him run
a "find . -type d ..." invoking "grep {}/*" for each directory found.
Other worthwhile suggestions have been offered which probably work
better for what he probably had in mind; however, I am surprised no one
mentioned the straightforward

	find . -type d -print | while read dir;do
		grep string $dir/*
	done

I don't know any way to do that sort of thing under C-shell, but Bourne
shell and successors handle it fine. There is this incredible feeling of
power in being able to type

	oifs=IFS
	IFS=":"
	while read login passwd uid gid tail;do
		# some processing for all the logins on the system
	done </etc/passwd
	IFS=oifs

whenever I feel like it.

-Bennett
bet at orion.mc.duke.edu



More information about the Comp.unix.wizards mailing list