Mac search for words in text file

broken image
broken image

Don't forget to make the script executable, e.g., with the command line: $ chmod +x /whatever/path/pat- CUT HERE - #!/bin/sh -# This script greps files matching a pattern under the current folder.# EXAMPLES# To display a list of files under the current directory# containing the word 'hello' ignoring case, use:# $ pat -li hello# To display, under the current directory, the actual lines in files# with the `.txt' extension containing either 'hello' or 'world':# $ pat 'hello|world' *.txt#PATH=/bin:/usr/binUSAGE='usage: pat egrep-pattern ]'typeset -i ii=0for arg do case '$arg' in -) break -*) egrep_arg='$arg' *) egrep_arg='$arg' break esacdone(( i>0 )) || shift $i find_arg='-type f'for arg do case '$arg' in -) (( ++i )) break *) if (( i=0 )) then find_arg='-a \( -name '$arg'' else find_arg='-or -name '$arg'' fi esacdone(( i>0 )) & find_arg='\)' shift $ieval find. Examples of how the command is used are contained in the comments of the script itself. To use it, copy the text below and save it (e.g., with TextEdit) to a file named `pat' in your current path (.e.g., /usr/bin/pat or preferably someplace like /opt/bin/pat, if that's in your path). Here is a script that reduces the syntax to a bare minimum for the most common usage - i.e., finding files containing strings. Select the extension for the file type you would like to include in content searches, and then select the Index Properties and File Contents option under the list. In the Advanced Options window, switch to the File Types tab.

broken image

It is faster to use find(1) with xargs(1), but then the syntax is a little more complicated. In the Indexing Options window, click the Advanced button.