Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!genrad!panda!talcott!harvard!seismo!vrdxhq!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.unix,net.unix-wizards,net.wanted Subject: Re: Need unix command file HELP! Message-ID: <259@hadron.UUCP> Date: Tue, 11-Feb-86 00:18:39 EST Article-I.D.: hadron.259 Posted: Tue Feb 11 00:18:39 1986 Date-Received: Thu, 13-Feb-86 17:42:04 EST References: <245@aero.ARPA> <587@smeagol.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 44 Xref: linus net.unix:6533 net.unix-wizards:13930 net.wanted:7470 Summary: grep won't always print file name! All the folk who are responding that the way to get the file names of files containing a particular string are kind of forgetting that the grep family does n o t automatically print out file names. This: >find / -exec fgrep this-is-the-string '{}' \; will give a file full of lines containing this-is-the-string. Try: find / -exec grep this-is-the-string '{}' /dev/null \; **OR** (quicker) : find / -type d -a -exec ksh findstr "this-is-the-string" {} \; findstr: #!/bin/ksh # or /bin/sh str="$1" dir="$2" file="" text="" if [ ! -d "$dir" ]; then exit 1; fi cd "$dir" for file in *; do if [ ! -f "$file" ]; then continue; fi text=`file "$file" | grep text` if [ "" = "$text" ]; then continue; fi # if you want the complete text: # grep "$str" "$dir/$file" /dev/null # otherwise text=`grep "str" "$file" | line` if [ "" != "$text" ]; then echo "$dir/$file" fi done exit 0 -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}