By Alvin Alexander. Last updated: February 7, 2021
When using Unix or Linux, if you ever need to find all files that contain multiple strings/patterns, — such as finding all Scala files that contain 'try', 'catch', and 'finally' — this find/awk command seems to do the trick:
find . -type f -name *scala -exec awk 'BEGIN {RS=""; FS="\n"} /try/ && /catch/ && /finally/ {print FILENAME}' {} \;
As shown in the image below, all of the matching filenames are printed out. As Monk says, you’ll thank me later. :)
(I should mention that I got part of the solution from this gnu.org page.)
Update: My File Find utility
For a potentially better solution, see my File Find utility, which lets you search for multiple regex patterns in files.