I'd like to use find to report files under the following conditions:If the file contains the word SerializableThen report the file if it does NOT contain the wordserialVersionUIDSomething like: find . -name *.java -exec grep Serializable {} \; <magic stuff here> grep serialVersionUID {} \; -printSo am I smoking crack and would be better served by awk?Thanks for your help.
Using find to search and report files that have one but not two keywords inside
linux;awk;find
The -exec operand of find evaluates to true if the command succeeds (i.e. returns zero) and false if it fails (returns nonzero), so you can use the success/failure of grep as part of the expression used by find.Together with find's ! operand, which negates the following operand, you can search for files for which one grep command succeeds and another grep command fails:find . -name *.java \    -exec grep -q Serializable {} ; -a \    ! -exec grep -q serialVersionUID {} ; -a -printThe -q option tells grep not to print out anything; we're only interested in its return value.The -a operand isn't strictly required, but it doesn't slow things down and I like to use it when there's a possibility that the expression may grow even more complex and require -o or parentheses.