./replace
Enter the origional string:
..String.(.*)[}]](.*)
Enter the replacement string:
$1$2
This will replace (${String[${Me.Name}].Equal[Ben]}) with (${Me.Name.Equal[Ben]}) and ${String[${Target.Name}].Equal[Wolf]} to ${Target.Name.Equal[Wolf]}.
this script is writin for unix like systems, works fine with cygwin though, and I use it for tons of stuff, especially maintaining my web scripts. Here's the code:
Code: Select all
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
my $directory = `ls`;
if($directory !~ /replace_temp/) {
system("mkdir replace_temp");
}
print "Enter origional string: \n";
my $ostring = <STDIN>;
chomp($ostring);
print "Enter replacement string: \n";
my $nstring = <STDIN>;
chomp($nstring);
my @cat = `grep -P -H -m 1 "$ostring" *`;
foreach my $catline (@cat) {
(my $file, my $matching_strings) = split(/:/, $catline);
system("cp $file replace_temp\/");
}
#replace ..String.(.*)[}]](.*) with $1$2
my @ls = `ls replace_temp`;
chomp(@ls);
foreach my $dir (@ls) {
if($dir !~ /replace/ && $dir !~ /.new/) {
open(DIR, "$dir") || die "Can't open $dir";
open(NEWFILE, ">$dir.new") || die "Can't open $dir NewDir";
while(my $line = <DIR>) {
$line =~ s/$ostring/qq("$nstring")/gee;
print NEWFILE "$line";
}
close(DIR);
close(NEWFILE);
}
}
system("rm -rf replace_temp");

