perl -pi.bak -e "s/oldtext/newtext/g" *.txt
This works on my windows machine from the command line, but I don't want to the the back up file. Is there a way around it?
<edit>Well, crap. It didn't work on multiple files...
I've found many variations on this and none of them actually work.
Does anybody have a snippet of code for searching and replacing text in multiple files that they actually use on a regular basis?
I like this one (because I did it), but it keeps appending to the files for *each* occurance, so I know it's not quite right.
@AllDTA = glob('*.js');
foreach $FileName (@AllDTA) {
open(NOTES, "<$FileName") or die "Could not open $FileName for reading\n";
while (<NOTES>) {
$notelines .= $_;
}
close(NOTES);
open(NOTES, ">$FileName") or die "Cannot find $FileName - no such file or invalid path\n";
select(NOTES);
$notelines =~ s/5508 Hwy/5716 Hwy/g;
print $notelines;
close(NOTES);
}
</edit>
This works on my windows machine from the command line, but I don't want to the the back up file. Is there a way around it?
<edit>Well, crap. It didn't work on multiple files...
I've found many variations on this and none of them actually work.
Does anybody have a snippet of code for searching and replacing text in multiple files that they actually use on a regular basis?
I like this one (because I did it), but it keeps appending to the files for *each* occurance, so I know it's not quite right.
Code:
chdir('P:\Mike\JS') or die "cannot connect to P: \n"; @AllDTA = glob('*.js');
foreach $FileName (@AllDTA) {
open(NOTES, "<$FileName") or die "Could not open $FileName for reading\n";
while (<NOTES>) {
$notelines .= $_;
}
close(NOTES);
open(NOTES, ">$FileName") or die "Cannot find $FileName - no such file or invalid path\n";
select(NOTES);
$notelines =~ s/5508 Hwy/5716 Hwy/g;
print $notelines;
close(NOTES);
}
</edit>