Taking Grep to a Lower Level

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: G.D.Thurman
Date:  
Subject: Taking Grep to a Lower Level
# 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