global search and replace

Jeff Kinz jkinz at kinz.org
Tue May 13 09:48:36 EDT 2003


On Tue, May 13, 2003 at 09:41:23AM -0400, Greg Rundlett wrote:
> I am a web developer, so I have large collections of text files (PHP,
> HTML, JS, etc.) that often need to be manipulated en-masse.  For the
> moment, I'm doing a complete re-design of the application that runs our
> website, and I need to effortlessly do text search and replace
> operations on thousands of files.
> 
> I spent the day yesterday upgrading my Quanta Plus install (hoping the
> feature was available in the newest version), and looking online for
> various ways to do a simple text replacement across thousands of files. 
> I know that there are perl scripts that with the proper care will do
> what I want, but why isn't this feature built-in to VIM, Quanta, or
> other editors?  AFAIK, the only editor that does this on Windows is
> HomeSite.
> 
> The thing I liked about HomeSite was that it could do the global search
> part alone, and display a list of clickable results so that you could
> really test out the operation first.  If everything looked hunky-dory,
> then you just do the search and replace operation.
> 
> It has been so long since I used perl, that I have to dig through my
> books and old code snippets even to find and understand the recipes that
> I come across.
> 
> How do you do this?




Replacing occurances of string in all files

perl -i -pe 's/red rose/blue ball/g' *.*

changes every occurance of the words red rose in all files in current dir to
blue ball 



-- 
Jeff Kinz, Open-PC, Emergent Research,  Hudson, MA.  jkinz at kinz.org
copyright 2003.  Use is restricted. Any use is an 
acceptance of the offer at http://www.kinz.org/policy.html.
Don't forget to change your password often.



More information about the gnhlug-discuss mailing list