old-www/LDP/LG/issue68/tag/6.html

232 lines
8.7 KiB
HTML

<!--startcut ======================================================= -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<META NAME="generator" CONTENT="lgazmail v1.3E.w">
<TITLE>The Answer Gang 68: LG 24 - Tips: Yet another way to find</TITLE>
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000"
LINK="#3366FF" VLINK="#A000A0">
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<P> <hr>
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</p>
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
<p align="center">
<table width="100%" border="0"><tr>
<td align="right" valign="center"
><IMG ALT="" SRC="../../gx/navbar/left.jpg"
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0"
><A HREF="..//"
><IMG SRC="../../gx/navbar/toc.jpg" align="middle"
ALT="[ Table Of Contents ]" border="0"></A
><A HREF="../lg_answer68.html"
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
ALT="[ Answer Guy Current Index ]" border="0"></A></td>
<td align="center" valign="center"><A HREF="../lg_answer68.html#greeting"><img align="middle"
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A> &nbsp;
<A HREF="bios.html">bios</A> &nbsp;
<A HREF="1.html">1</A> &nbsp;
<A HREF="2.html">2</A> &nbsp;
<A HREF="3.html">3</A> &nbsp;
<A HREF="4.html">4</A> &nbsp;
<A HREF="5.html">5</A> &nbsp;
<A HREF="6.html">6</A> &nbsp;
<A HREF="7.html">7</A> &nbsp;
<A HREF="8.html">8</A> &nbsp;
<A HREF="9.html">9</A> &nbsp;
<A HREF="10.html">10</A> &nbsp;
<A HREF="11.html">11</A> &nbsp;
<A HREF="12.html">12</A>
</td>
<td align="left" valign="center"><A HREF="../../tag/kb.html"
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
ALT="[ Index of Past Answers ]" border="0"></A
><IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
WIDTH="14" HEIGHT="45" BORDER="0"></td></tr></table>
</p>
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<center>
<H1><A NAME="answer">
<img src="../../gx/dennis/qbubble.gif" alt="(?)"
border="0" align="middle">
<font color="#B03060">The Answer Gang</font>
<img src="../../gx/dennis/bbubble.gif" alt="(!)"
border="0" align="middle">
</A></H1>
<BR>
<H4>By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and the Gang,
the Editors of Linux Gazette...
and You!
<br>Send questions (or interesting answers) to
<a href="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</a>
</H4>
<p><em><font color="#990000">There is no guarantee that your questions
here will <b>ever</b> be answered. Readers at confidential sites
must provide permission to publish. However, you can be published
anonymously - just let us know!
</font></em></p>
</center>
<p><hr><p>
<!-- endcut ======================================================= -->
<!-- begin 6 -->
<H3 align="left"><img src="../../gx/dennis/qbubble.gif"
height="50" width="60" alt="(?) " border="0"
>LG 24 - Tips: Yet another way to find</H3>
<p><strong>From Bill Thompson
</strong></p>
<p align="right"><strong>Answered By Ben Okopnik
<br></strong></p>
<!-- sig -->
<P><STRONG>
Hi,
</STRONG></P>
<P><STRONG>
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.
</STRONG></P>
<P><STRONG>
PLEASE help!
</STRONG></P>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [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.
</BLOCKQUOTE>
<BLOCKQUOTE>
As an example, in 'grepfind' you have the following lines:
</BLOCKQUOTE>
<blockquote><code><font color="#000033"><br>if [ "$2" = "" ]; then
<br>find . -type f -exec egrep -i "$1" /dev/null {} \; | sed -e 's/[^ -~][^-~]*/ /g'
</font></code></blockquote>
<BLOCKQUOTE>
(This is the "single-argument" mode, so that's how you'd test it.) Try
eliminating the "sed" part:
</BLOCKQUOTE>
<blockquote><code><font color="#000033"><br>if [ "$2" = "" ]; then
<br>find . -type f -exec egrep -i "$1" /dev/null {} \;
<br># | sed -e 's/[^ -~][^-~]*/ /g'
</font></code></blockquote>
<BLOCKQUOTE>
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:
</BLOCKQUOTE>
<blockquote><code><font color="#000033"><br>if [ "$2" = "" ]; then
<br>find . -type f
<br># -exec egrep -i "$1" /dev/null {} \;
<br># | sed -e 's/[^ -~][^-~]*/ /g'
</font></code></blockquote>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<BLOCKQUOTE>
Good luck.
</BLOCKQUOTE>
<P><STRONG><IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
Ben,
</STRONG></P>
<P><STRONG>
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.
</STRONG></P>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [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.
</BLOCKQUOTE>
<!-- end 6 -->
<!--startcut ======================================================= -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 2001
<BR>Published in issue 68 of <I>Linux Gazette</I> July 2001</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<P> <hr>
<P> <hr>
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</p>
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
<p align="center">
<table width="100%" border="0"><tr>
<td align="right" valign="center"
><IMG ALT="" SRC="../../gx/navbar/left.jpg"
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0"
><A HREF="..//"
><IMG SRC="../../gx/navbar/toc.jpg" align="middle"
ALT="[ Table Of Contents ]" border="0"></A
><A HREF="../lg_answer68.html"
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
ALT="[ Answer Guy Current Index ]" border="0"></A></td>
<td align="center" valign="center"><A HREF="../lg_answer68.html#greeting"><img align="middle"
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A> &nbsp;
<A HREF="bios.html">bios</A> &nbsp;
<A HREF="1.html">1</A> &nbsp;
<A HREF="2.html">2</A> &nbsp;
<A HREF="3.html">3</A> &nbsp;
<A HREF="4.html">4</A> &nbsp;
<A HREF="5.html">5</A> &nbsp;
<A HREF="6.html">6</A> &nbsp;
<A HREF="7.html">7</A> &nbsp;
<A HREF="8.html">8</A> &nbsp;
<A HREF="9.html">9</A> &nbsp;
<A HREF="10.html">10</A> &nbsp;
<A HREF="11.html">11</A> &nbsp;
<A HREF="12.html">12</A>
</td>
<td align="left" valign="center"><A HREF="../../tag/kb.html"
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
ALT="[ Index of Past Answers ]" border="0"></A
><IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
WIDTH="14" HEIGHT="45" BORDER="0"></td></tr></table>
</p>
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
</BODY></HTML>
<!--endcut ========================================================= -->