ram@wgivax.UUCP (02/04/86)
> If you only want the file names, this *might* work, I'm not sure ... > find / -exec "fgrep this-is-the-string '{}' | awk -F: '{print $1}'" \; > (DOUBLE UGGGHHH) > -- Or maybe... find / -exec "fgrep this-is-the-string '{}' | awk '{print FILENAME}'" \;
mo@wgivax.UUCP (02/04/86)
> from ram@wgivax >> If you only want the file names, this *might* work, I'm not sure ... >> find / -exec "fgrep this-is-the-string '{}' | awk -F: '{print $1}'" \; >> (DOUBLE UGGGHHH) >> -- > Or maybe... > find / -exec "fgrep this-is-the-string '{}' | awk '{print FILENAME}'" \; --------------------------- FLAME ON! --------------------------------------- WILL YOU PEOPLE PLEASE RTFM BEFORE MAKING SUGGESTIONS ABOUT HOW TO HELP WITH PROBLEMS? ADMITTEDLY THE FIRST WILL WORK, BUT WILL PRINT OUT THE FILE NAME FOR EVERY OCCURRENCE OF THE STRING IN A GIVEN FILE! THE SECOND "SUGGESTION" WILL PRINT OUT "-" FOR EVERY OCCURRENCE OF THE STRING IN EVERY FILE IT IS FOUND IN! (-: WHAT A HAPPY SUPRISE FOR THE PERSON WHO WAITS 12 HOURS FOR IT TO RUN, REDIRECTING IT INTO A FILE, TO FIND THAT ALL THE WORK WAS A WASTE :-) NOTE THAT BOTH SUGGESTIONS WOULD BE RUNNING NUMEROUS AWKS, ADDING AWK'S STARTUP COSTS FOR EACH AND EVERY FILE, DIRECTORY, DEVICE, ETC. IN THE SYSTEM (-: MAYBE 12 HOURS IS TOO LOW AN ESTIMATE, MAYBE 12 DAYS WOULD BE BETTER, UNLESS YOU'RE RUNNING A CRAY OR AN IBM-PC :-) --------------------------- FLAME OFF! -------------------------------------- OK, now that I have that out of my system, I will re-post a solution which I have fully TESTED (-: interesting idea, to test something before offering it as a solution, no? :-). find / -type f -exec fgrep -l "string" {} \; caveat emptor: (let the buyer beware, for those without high school latin) ALWAYS TRY SOMETHING LIKE THIS ON A SMALL SUBSET OF THE FILES WHICH ARE TO BE INCLUDED! LIKE: "find ~ ..."
mike@whuxl.UUCP (BALDWIN) (02/05/86)
> > find / -exec "fgrep this-is-the-string '{}' | awk -F: '{print $1}'" \; > > find / -exec "fgrep this-is-the-string '{}' | awk '{print FILENAME}'" \; Gak! NEITHER of these has any chance of working! The args to -exec are passed to execvp(), so you can't just pass an arbitrary shell cmd to it (this is on System V). Also, {} is only substituted if it is a *separate* arg. If you want to put a pipeline into -exec with the filename, you have to: find dir -exec /bin/sh -c 'prog1 $1 | prog2 $1' sh {} ';' The $1 is used to pull in the {}, and the sh in front of {} is $0. But ANYWAY, that still wouldn't fix it. The $1 in the first one will get substituted because it's in double quotes, and the FILENAME in the second one will print "-", standard input. Anybody ever heard of the -l option to *grep??? Try this: find / -type f -exec grep -l string {} ';' Better yet, if you're on SV you can use xargs to bundle the files up and save considerable amounts of time: find / -type f -print | xargs grep -l string In the future, *please* give examples that at least have a chance of working (i.e., try them once). -- Michael Baldwin (not the opinions of) AT&T Bell Laboratories {at&t}!whuxl!mike