On Sun, 2 Jan 2005 17:11:59 -0500, Jonathan Levi MD <[EMAIL PROTECTED]> wrote:... search for the presence of a user-supplied string in an arbitrary number of files?
On 3 Jan 2005, at 9:35 AM, miket wrote:
[re-adding fink-users]
$ grep -e "STRING" -f "/path/to/FILE1" "/path/to/FILE2"
or if all your files are in the same directory
$ grep -e "STRING" -r "/path/to/directory/"
the -e isnt necessary but its nice to be explicit incase youre string has special characters. You can get grep via fink but its probably already installed (usually part of a stock install for OS X)
Or, if you need more control over which files to include in the search, you can use find(1). For instance the following will search all .txt files in your home directory (and all subdirectories recursively)
$ find ~ -name "*.txt" -exec grep -H -e "STRING" {} \;You can find files based on filename, modification time, filetype etc... see the find(1) man page.
You might also find xargs(1) useful. xargs runs a command passing what it is given on stdin as arguments. So an alternative way of doing the above is:
$ find ~ -name "*.txt" | xargs grep -e "STRING"
If you have filenames with spaces in the names, you'll need to tell find(1) and xargs(1) to delimit arguments with a null instead of a space using the following:
$ find ~ -name "*.txt" -print0 | xargs -0 grep -e "STRING"
Or maybe you don't need to use find, because you have the list of filenames somewhere, in which case you can do:
$ cat /tmp/filelist | xargs grep -e "STRING"
-- Rohan Lloyd
------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ Fink-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/fink-users
