[Chicago-talk] replace in place
Jason Gessner
jason at multiply.org
Sat Mar 12 20:33:51 PST 2005
also, you can add an extension to -i like -i.bak to have the original
files backed up.........
Comes in handy if you aren't *quite* sure about what you are doing. :)
-jason gessner
jason at multiply.org
On Mar 11, 2005, at 2:55 PM, Greg Fast wrote:
> On Fri, 11 Mar 2005 14:29:51 -0600, Andy Lester <andy at petdance.com>
> wrote:
>> 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
>> 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.
>
> This is a good trick too:
>
> find . -name \*.java | xargs perl -ipe 's/public/private/'
>
> especially when you need complex findage, your file count starts to
> bump up against the command length limit of your shell (usually ~1024
> characters). And if some of your filenames might have spaces or other
> unsafe chars in them, "find ... -print0 | xargs -0 perl ..." rules.
>
> Oh, and since perl -pe was mentioned, I'm karmically obliged to give a
> shout out for
>
> perl -MO=Deparse -i@@ -pe 's/foo/bar/' Makefile
>
> --
> Greg Fast
> http://cken.chi.groogroo.com/~gdf/
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
More information about the Chicago-talk
mailing list