Well, considering this is perlmonks, not sedmonks, I can give you a solution that happens to use perl intrinsically rather than spawning sed.
open F1, "< $write" or die $!;
open F2, "> $write2" or die $!;
while (<F1>) {
s/$search/$replace/ig;
print F2 $_;
}
close F1;
close F2;
Depending on what you're doing, you might be able to avoid the external files altogether.
jdporter The 6th Rule of Perl Club is -- There is no Rule #6. | [reply] [d/l] |
Did you know that Perl can do just about everything sed can do? A straight-across port might be:
system qq|perl -e 's/$search/$replace/gi' $write > $write2|;
I'd likely do it in-process, though.
| [reply] [d/l] [select] |
Though the other answers are probably more desirable, just for comparison, here's what you actually asked for (untested): # You may also want additional substitutions
# to backwhack sed metacharacters, e.g.
# $search =~ s/\./\\./g;
$search =~ s/([[:alpha:]])/"[".lc($1).uc($1)."]"/ge;
system "sed -e s/$search/$replace/g $write1 > $write2";
But it's much easier to use the case insensitive regex switch in perl :-)
Update: Updated code. In reply to AM: I'm just creating sed character classes, which, e.g., replaces "a" with "[aA]" to make it case insensitive. | [reply] [d/l] [select] |
can u explain me what u did to $search please
thank you
| [reply] |
| [reply] |