Você não nos disse o que realmente quer fazer. Estou supondo que você queira truncar os arquivos que não contêm nenhuma de suas palavras-chave (pelo menos é o que parece).
Se você quiser que grep corresponda apenas a palavras inteiras, use o sinalizador -w . De man grep :
-w, --word-regexp
Select only those lines containing matches that form whole
words. The test is that the matching substring must either be
at the beginning of the line, or preceded by a non-word
constituent character. Similarly, it must be either at the end
of the line or followed by a non-word constituent character.
Word-constituent characters are letters, digits, and the
underscore.
Além disso, grep não pode aceitar vários padrões como argumentos. Seu comando será expandido por bash para
grep -qF Alachua Gainesville Hawthorne
Isto significa " procurar por Alachua nos arquivos Gainesville e Hawthorne ". Para passar vários padrões para grep , é necessário separá-los com | (você precisará ativar expressões regulares estendidas com -E ) ou salvá-los em um arquivo e passar esse arquivo para grep usando -f :
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file
contains zero patterns, and therefore matches nothing. (-f is
specified by POSIX.)
Por exemplo, em seu script você pode criar um arquivo temporário, salvar os padrões nele e depois grep (não há razão para definir IFS aqui):
#!/usr/bin/env bash
KEYWORDS=("Alachua" "Gainesville" "Hawthorne")
## Create a temporary file
tmp=$(mktemp);
## Save your keywords in that file
for word in "${KEYWORDS[@]}"; do
echo $word >> "$tmp";
done
## Now run your find command and tell grep
## to read the patterns from the temp file
find . -size +1c -type f ! -exec grep -qwFf "$tmp" {} \; -exec truncate -s 0 {} \;
Como alternativa, crie seu padrão juntando suas strings de interesse com | e execute grep com -E para expressões regulares estendidas:
#!/usr/bin/env bash
patterns="Alachua|Gainesville|Hawthorne";
find . -size +1c -type f ! -exec grep -Eqw "$patterns" {} \; -exec truncate -s 0 {} \;