Forum Moderators: phranque

Message Too Old, No Replies

Tool to do Search & Replace

like a text editor?

         

chewy

4:33 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I like using textpad's s&r function (and the macros!) but I can't seem to figure out an easy way to do s&r across all files in a directory.

Yes, I can use Dreamweaver but prefer using something simpler.

Is there a tool I should be using?

By the way, other tools I love are winhttrack and xenu.

tx,

C.

bcolflesh

4:37 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ReplaceEm has been mentioned here before:

[boolean.ca...]

chewy

4:48 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



just the ticket!

Thanks!

txbakers

5:41 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



textpad will do s & r for all the files in a directory.

Matt Probert

7:24 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And here is a very simple, but quick and effective Perl program to search and replace every file in the current directory.

NB: This program assumes that all files are ASCII (eg: HTML files), it could do untold damage to binary files!

# Very simple search and replace in Perl
# Use PERL SR.PL <string to find> <replacement string>

$find = $ARGV[0];
$replace = $ARGV[1];

#Open directory
opendir(DIR, ".");

@fnames=readdir(DIR);

foreach $file (@fnames)
{
open(FILE, $file);
open(TGT, ">sr.tmp");

while (<FILE>)
{
# Here we are using a case insensitive transformation
# change the /gi to /g for case sensistive

$_ =~ s/$find/$replace/gi;
print TGT "$_";
}
close(FILE);
close(TGT);

rename ("sr.tmp",$file);
}

Matt