Newsgroups: comp.unix.questions Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Subject: Re: grep Message-ID: <1991Apr15.174734.8413@athena.mit.edu> Keywords: grep, recursive Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology References: <1991Apr14.214414.9815@hellgate.utah.edu> Date: Mon, 15 Apr 91 17:47:34 GMT Lines: 56 In article <1991Apr14.214414.9815@hellgate.utah.edu>, mmoore%hellgate.utah.edu@cs.utah.edu (Michael Moore) writes: |> I don't know what to do. If there were a way to recursively cat |> files or something similar, I could pipe that to grep, but I can't find that |> either. find dirname -type f -exec grep pattern {} \; find dirname -type f -print | xargs grep pattern find dirname -type f -exec cat {} \; | grep pattern If there aren't a lot of files in the directory tree: grep pattern `find dirname -type f -print` The first solution mentioned will start up a grep process once for each file you want to search, so if there are a lot of files it will be slow. Therefore, if your system has xargs, and if there are no funky characters (such as newlines) in the filenames, the second solution is probably better. If you don't have xargs, there are several versions of it available on the net. The third solution mentioned probably has no advantages over the previous solutions so you probably shouldn't use it; I mention it just to answer your question about recursive cat'ing. The fourth solution is the best if there are few enough files in the tree that they will all fit in the maximum length of a command line. Quotining from question 3 of the "Frequently Asked Questions about Unix - with Answers [Monthly posting]" posting in this newsgroup, "`find' is a powerful program. Learn about it." It's a good idea to read that posting if you haven't already. If it has expired at your site, you can get a copy of it using the instructions at the end of this message. Oh, of course, you could do this in perl too, and perl would do the recursive file search and the grep all in one process. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710 -- Subject: Frequently Asked Questions about Unix - with Answers [Monthly posting] Newsgroups: comp.unix.questions Available via anonymous ftp from pit-manager.mit.edu (18.72.1.58) in the file /pub/usenet/comp.unix.questions/Frequently_Asked_Questions_about_Unix_-_with_Answers_[Monthly_posting] Available from mail-server@pit-manager.mit.edu by sending a message containing send usenet/comp.unix.questions/Frequently_Asked_Questions_about_Unix_-_with_Answers_[Monthly_posting] Send a message containing "help" to get general information about the mail server.