I'm trying to figure out which keywords are being found for [each] file in the script below. I tried adding echo $keywords and it just outputs every keyword.


keywords=("Alachua" "ALACHUA" "alachua" "Archer" "Gainesville" "Hawthorne" "High Springs" "Newberry" "Waldo" "LaCrosse" "PA-LOCKA" "PALMETTO BAY" "PINECREST" "34997")
find . -size +1c -type f ! -exec grep -qwF "${keywords[*]}" {} \; -exec truncate -s 0 {} \;   


My issue is I have far more keywords than in this example and I'm not sure which one(s) are being found in EVERY file and I need to remove it from $keywords as it's messing up my results.

  • 2
    General rule: Please give an example file as input and the output you see. I cannot reproduce the effect you describe. Mar 25, 2014 at 18:31

1 Answer 1


There are several problems:

  1. You confuse "${keywords[*]}" with "${keywords[@]}". The former expands to one argument.

  2. -q inhibits any output.

  3. If you have several patterns you cannot pass them as a list of arguments. You need -e pattern1 -e pattern2 instead. Or you must pass them in a file (see -f).

I guess awk makes more sense in this case.

This may be useful:

awk -v patternfile=pattern \
'BEGINFILE {i=0; while(getline var <patternfile) {pattern[i]=var;i++}; '\
'no_patterns=i; close(patternfile)}; '\
'FNR == 1 {print ""; print "file: " FILENAME;}; '\
'{for (i in pattern) { if($0 ~ pattern[i]) {print pattern[i]; delete pattern[i]};}}' \
file file2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .