Page 1 of 1

Search for Text in File without relying on Spotlight Index

PostPosted: Tue Aug 07, 2012 1:32 pm
by a_freyer
There have been a number of users wondering how to search the text of a file (OCR'd documents, unusual extensions) whose metadata is not recorded in Spotlight.

Here is the 1-Step solution:

Step 1: Add Returns shell script condition to rule.

Code: Select all
exit $([ $(grep -ci "the text that you want to find" "$1") -gt 0 ])


This script will match a file (i.e. return 0) when text you want to find is found at least once within the text of the file being matched.

EDIT - enclosed $1 in quotes to prevent unescaped path errors.