Date: Fri, 28 Dec 2001 13:22:52 -0500 From: Simon Morton <simon.morton@verizon.net> To: FreeBSD Questions <freebsd-questions@FreeBSD.ORG> Subject: Re: [Fwd: Re: How To Recursively Search Directory For Text String In Files?] Message-ID: <3C2CB87C.90000@verizon.net>
next in thread | raw e-mail | index | archive | help
Roman Neuhauser wrote: > I think you should pay a wee bit more attention to what you read: > > "What I want to do is search all files in my current directory and > all the directories below it for a text string and then know what > file(s) contains the string." Well, since you mentioned it, if you had paid "a wee bit more attention" to the problem statement you would have known that only the names of matching files were required, not all matching strings plus file names and line numbers. Nor did it stipulate case-insensitive search or excluding binary files. So the correct solution would actually be "grep -Flr pattern path". So much for reading comprehension skills. > Simple task, simple solution. I don't know what good would the > original poster achieve by using find, xargs and grep where simple > grep does the work. Of course, it's easy to get carried away, but > one should discriminate between use and abuse. I agree that xargs adds no value here. My solution only used find and grep. What is to be gained by doing so? Maybe the opportunity to learn not just the solution to the immediate problem but perhaps also a tool that could be of use solving similar but more complex problems in the future. "Give a man a fish, feed him today. Teach a man to fish, feed him for life". "grep -Flr pattern path" solves the problem asked using the minimum number of characters. This also was not a requirement. "find path -exec grep -Fl pattern {} \;" uses 16 more characters to do the same job while providing a template for more complex searches as well as a much better illustration of the "Unix philosophy". If you call this insanely complicated then you don't truly appreciate the beauty and power that is Unix. Simon -- http://www.SimonMorton.com smorton at acm dot org \rm -rf /bin/laden -- http://www.SimonMorton.com smorton at acm dot org \rm -rf /bin/laden To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C2CB87C.90000>