[PLUG] text search/replace

Rogan Creswick creswick at cs.orst.edu
Thu Feb 13 21:29:01 UTC 2003


If you need to do this in only one file, then most text editors worth
their name can do it for you. in vi:

:1,$s/oldexpr/newexpr/g 

will do it. emacs has the ability also, but the keystrokes to do so
escape me at the moment.

If you need to do so on many files there are any multitude of ways to
do this in perl alone (not to mention awk, etc..).

this should work:

perl -pi -e "s/oldexpr/newexpr/g" file1 file2 file3

or use find to locate the files..

find . -name "*.lisp" -print | xargs perl -pi -e "s/oldexpr/newexpr/g"

to apply the reg.exp to all lisp files in this directory and it's sub
dirs (the -print is optional with many versions of find).

hth.
Rogan

On Thu, Feb 13, 2003 at 09:19:35PM -0800, Scott Van Hoosen wrote:
> I'm interested in finding a simple, text-based utility
> to search for text recursively (like grep) then
> replace that text with new text. I've had my eye out
> for something like this for a long time, and I'm sure
> it exists, but I just haven't come across it.
> 
> Any suggestions?
> 
> -Scott
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Shopping - Send Flowers for Valentine's Day
> http://shopping.yahoo.com
> 
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug




More information about the PLUG mailing list