[Chicago-talk] replace in place

Andy Lester andy at petdance.com
Fri Mar 11 12:29:51 PST 2005


On Fri, Mar 11, 2005 at 02:20:20PM -0600, JT Smith (jt at plainblack.com) wrote:
> I remember having a really great tutorial on doing things in one line from 
> the command line in perl, but I can't remember how it all worked. Could 
> somebody help me out? I have a make file that has a line in it I wish to 
> replace. The line looks like:

"A Field Guide To The Perl Command-Line Options" at
http://www.petdance.com/perl/

> prefix=/usr/local
> 
> And I would like it to be
> 
> prefix=/data/prereqs

 perl -i -p -e's[/usr/local][/data/prereqs]g' Makefile

or

 perl -i -p -l -e'$_ = "prefix=/data/prereqs" if $_ eq "prefix=/usr/local"' Makefile

You can replace

    Makefile

with

    `find . -name Makefile`

to find all Makefiles in the tree if you like.


-- 
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance


More information about the Chicago-talk mailing list