Search for Files that DONT contain a string

How do I search for files that dont contain a certain string? I am currently trying

find ./logs -size +1c -exec grep -l 'Process Complete' {} \; -exec ls -l {} \; >
$TOD

Which gives me files that are reater han 0 file size and contain the string 'Process complete' but I want files that DONT contain Process Complete. If i use the -v option for grep it still doesnt work!

Try

find ./logs -size +1c  > t._tmp
while read filename
do
     grep -q "Process Complete" $filename
     if [ $? -ne 0 ] ; then
             echo $filename
     fi
done < t._tmp
rm -f t_tmp

Just negate the condition with a "!"

find ./logs -size +1c ! -exec grep -l 'Process Complete' {} \; -exec ls -l {} \; >$TOD

This doesnt seem to be working as it is still picking up the files with Process Complete in them. I have tried moving the ! around but still no joy. 'Process Complete' should only be on the last line of the file if that helps.

I think that your problem is that you are using find to grep on the ./logs directory itself and not just on the files in that directory. You need to restrict the find to only grep within plain files.

Lets test this theory, using some test files...

$ mkdir logs
$ echo 'Process Complete' > logs/log1
$ echo 'otherwise' > logs/log2

...first find files that do contain the string...

$ find ./logs -size +1c -exec grep -q 'Process Complete' {} \; -print
./logs/log1

...as expected. Now find files that do NOT contain the string...

$ find ./logs -size +1c ! -exec grep -q 'Process Complete' {} \; -print
./logs
./logs/log2

...woah! What's that "./logs" thing doing there?! If I was using "-exec ls -l {} \;" then it would return every file in the directory! Better restrict the find to plain files...

$ find ./logs -type f -size +1c ! -exec grep -q 'Process Complete' {} \; -print
./logs/log2

...OK!

Thank you, this does seem to work but I get an error with the -q option so I have changed it to -l, what should it do though ?

What kind of grep does not have the -q option?

grep -q returns true if the string is found or false, and prints no output to stdout.

You test the return value to see if the string was there or not.

Thanks Jim.I dont know what grep doesnt have the -q option, all I know is that I get this error when I try to use it:

UX:grep: ERROR: Illegal option -- q
UX:grep: TO FIX: Usage: grep -hblcnsvi pattern file . . .

Tony, run the command "uname -a" and tell us what it says. I also am wondering which version of unix you are using.

The -q option on grep is required by posix. So it would seem that your version of unix is not posix compliant.

I have run uname -a and I get:

dgux hs-it-a5-59 R4.11MU06 generic AViiON mc88110

Bravo, Ygor! I came to these forums KNOWING that the answer must dwell within. Registered, searched, and found--1st try :slight_smile:

Thank you!

For me, I wanted to find any instance of our "old" domain name, while EXCLUDING email addresses. Finally!

find . -type f ! -exec grep -q '@olddomain.com' {} \; -exec grep -q 'olddomain.com' {} \; -print

Just try

  grep -rL 'Process Complete' ./logs

cd logs
grep -v 'Process Complete' *