Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site wgivax.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!houxm!whuxl!whuxlm!akgua!mcnc!unccvax!wgivax!mo From: mo@wgivax.UUCP Newsgroups: net.unix,net.unix-wizards,net.wanted Subject: Re: Need unix command file HELP! Message-ID: <144@wgivax.UUCP> Date: Sat, 15-Feb-86 07:15:49 EST Article-I.D.: wgivax.144 Posted: Sat Feb 15 07:15:49 1986 Date-Received: Mon, 17-Feb-86 04:59:54 EST References: <245@aero.ARPA> <587@smeagol.UUCP>, <259@hadron.UUCP> Lines: 55 Xref: watmath net.unix:7117 net.unix-wizards:16801 net.wanted:8171 >From jsdy@hadron.UUCP (Joseph S. D. Yao) Sun Feb 6 01:28:16 206 >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 \; WRONG! fgrep -l WILL print the file name, and WILL NOT print the string it will look for ONLY the first occurrence in a file, speeding things up, AND fgrep is faster than grep >**OR** (quicker) : > >find / -type d -a -exec ksh findstr "this-is-the-string" {} \; (-: GREAT, NOW HOW DO I FIND THE KORN SHELL ? :-) >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 this is admittedly "safer", since it skips non-text files, but look at all those sub-processes you're starting up for every used inode on the system! haven't we heard enough about this, YET?