I have a list of words (these are actually a list of database table names separated by comma).
Now, I want to find only the non-existing list of words in the *.java files of current directory and/or its sub-directories.
Sample list of words: table_one,table_ten,table_x,table_y,table_z
Type of files in current directory and/or its sub-directories: *.java
Suppose, 2 words (say table_ten and table_z) are not exist in any of the *.java files in current directory and/or its sub-directories, then print these 2 words as output as shown below.
What have you tried? (It's easier and quicker for forum members to help you from where you're stuck; rather than give you a solution they have to work from scratch, just for you)
To help you get started, you could try a combination of find and grep . Let us know what you could come up with.
for file in $(find /path/to/dir -type f -name "*java")
do
for word in table_one table_two table_three
do
if grep -q $word $file
then
continue
else
echo "$file does not contain $word"
fi
done
done
Try (untested, assuming table names in a one line file):
awk -F, '
NR == 1 {for (n=split($0, T); n>0; n--) TBL[T[n]]=n
next
}
$0 in TBL {delete TBL[$0]
}
END {print "non-existing:"
for (t in TBL) print t
}
' tblfile *.java