Taking Grep to a Lower Level

G.D.Thurman plug-discuss@lists.plug.phoenix.az.us
Tue, 5 Nov 2002 19:09:30 -0700 (MST)


# list the name of files containing the pattern foo
# should work on sh, bash and ksh

for fname in `find . -type f 2>/dev/null` ; do
   file $fname 2>/dev/null | grep text 1>/dev/null 2>&1 && grep -l foo $fname
done

# manpage for 'file' indicates that most files that can be displayed 
# on a screen will have the word "text in their description