Tugger the SLUGger!SLUG Mailing List Archives

Re: [slug-chat] Another script challenge


On Fri, Apr 20, 2001 at 02:50:06AM +1000, Michael (Micksa) Slade wrote:

> Peter Hardy wrote:
> 
> > I want to replace every instance of 'gzip' occuring in a source tree with
> > bzip2.  This is how I did it:
> > 
> > for file in `grep -rl gzip *`
> > do cp $file $file.old
> > sed s/gzip/bzip2/ < $file.old > $file
> > done
> > 
> > But I'm sure there's a shorter solution.  Suggestions?
> 
> find . -type f -print0|xargs -0 perl -i -e -s "s/gzip/bzip2"
> 
> Your version is quicker, but mine handles filenames with spaces.

you can also do:

    find . -type f -print0 | perl -i -e -s -0 "s/gzip/bzip2/"

(perl -0 sets the input record separator to null)


-- 
#ozone/algorithm <ozone@xxxxxxxxxxxxxxxx>          - trust.in.love.to.save