Unix/Linux: Find all files that contain multiple strings/patternsalvinMay 9, 2019 - 5:47pm
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, 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.)