[ Table Of Contents ][ Answer Guy Current Index ] greetings   bios   1   2   3   4   5   6   7   8   9   10   11   12 [ Index of Past Answers ]

(?) The Answer Gang (!)


By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and the Gang, the Editors of Linux Gazette... and You!
Send questions (or interesting answers) to tag@lists.linuxgazette.net

There is no guarantee that your questions here will ever be answered. Readers at confidential sites must provide permission to publish. However, you can be published anonymously - just let us know!


(?) LG 24 - Tips: Yet another way to find

From Bill Thompson

Answered By Ben Okopnik

Hi,

I have been using grepfind since it was published in the LG 24 Tips column with great results. Since using Mandrake 8.0, it no longer works as before. It does it search but nothing is written to the display. The command-line returns as many lines down as the results of grepfind found. A friend using Mandrake 7.2 says grepfind works. Another friend using Mandrake 8.0 reported the same results as I get.

PLEASE help!

(!) [Ben] Bill, the only thing I can figure is that the syntax of 'find', 'sed', or 'grep' has been changed in the 8.0 distro. Nowadays, there are better ways to do what you want - as an example, my version of 'grep' (GNU 2.4.2) supports recursive searching via the "-r" switch - but if you want to find out what's bugging your script, try removing the "layers" one at a time.
As an example, in 'grepfind' you have the following lines:

if [ "$2" = "" ]; then
find . -type f -exec egrep -i "$1" /dev/null {} \; | sed -e 's/[^ -~][^-~]*/ /g'
(This is the "single-argument" mode, so that's how you'd test it.) Try eliminating the "sed" part:

if [ "$2" = "" ]; then
find . -type f -exec egrep -i "$1" /dev/null {} \;
# | sed -e 's/[^ -~][^-~]*/ /g'
Now run the script and see if you get reasonable output; if you do, the problem is in 'sed'. If you don't, the problem is in 'find' or 'egrep'; split them out like so:

if [ "$2" = "" ]; then
find . -type f
# -exec egrep -i "$1" /dev/null {} \;
# | sed -e 's/[^ -~][^-~]*/ /g'
This time, if the problem disappears, it's in 'egrep'; if it still doesn't, it's in 'find'. Check the appropriate manpage for whatever the syntax change may be; someone may have decided to go back to that perverted version of 'find' that requires "-print" in order to output anything (yechhh!), for example. After that, the only thing that's left is figuring out what the author wanted the function to do, and replacing the syntax with the new version that will do the same thing.
Good luck.

(?) Ben,

Thanks for the troubleshooting tip. 'sed' was the offender. I recompiled the original one from Mandrake 7.2 and now all's well. To date, I haven't experienced any fallout when 'sed' is used elsewhere.

(!) [Ben] It's interesting to note what subtle bugs can come up even in shell scripts over time (this, of course, was not a script bug but a GNU util, but still...) Glad that I was able to help, Bill.


This page edited and maintained by the Editors of Linux Gazette Copyright © 2001
Published in issue 68 of Linux Gazette July 2001
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/



[ Table Of Contents ][ Answer Guy Current Index ] greetings   bios   1   2   3   4   5   6   7   8   9   10   11   12 [ Index of Past Answers ]