- To: "Michael (Micksa) Slade" <micksa@xxxxxxxxxxxx>
- Subject: Re: [slug-chat] Another script challenge
- From: Andre Pang <ozone@xxxxxxxxxxxxxxxx>
- Date: Fri Apr 20 10:40:02 2001
- Cc: Peter Hardy <peterhardy@xxxxxxxxxx>, slug-chat@xxxxxxxxxxx
- User-agent: Mutt/1.3.17i
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