Maybe OT - Grepping the locate command

Kevin Hunter hunteke at earlham.edu
Wed Mar 3 16:04:44 GMT 2010


At 9:43am -0500 Wed, 03 Mar 2010, John McCabe-Dansted wrote:
> On Wed, Mar 3, 2010 at 10:11 PM, Kevin Hunter wrote:
>> At 6:36am -0500 Wed, 03 Mar 2010, donn wrote:
>>> On 03/03/2010 13:08, John McCabe-Dansted wrote:
>>>> so we need something a bit longer like. locate *.ods | while read f ;
>>>> do unzip -p $f | grep BLAH>  /dev/null &&  echo $f ; done
>>> Groovy. I added quotes to handle weird filenames:
>> 
>> Actually, even that can get you in to trouble.  If you want to be
>> robust, consider using a delimiter that *can't* be in the filename.  For
>> example, the NUL byte:
> 
> Could you demonstrate the problem? Using quotes seems to work fine on
> files with "'s in the filename.

As that was off the top of my head, no.  I don't have an example handy.
 And for this use case, it's perhaps overkill.

Where it might get you into trouble is if you have a slightly more
complicated setup; for example, if you have nested set of loops, or are
messing with files that have weird characters.

Note, though, that "robust" vs "works-for-me" is specific to a need, and
very much "your" call.  I was highlighting a way to be much more robust,
for not too much extra work.

Kevin



More information about the sounder mailing list