Ria Ria - 27 days ago 6
Perl Question

In-place edits using sed on OS X

I have seen multiple posts on Stack overflow with various solutions to this problem. I tried various versions of posted solution, but I can't get it to work.

I am writing a perl script where I want to

my $fileName = "apple";
my $newName = "banana";
my $ tmpPath = "/etc/ria";
["/usr/bin/sed","-i ''", "s/${fileName}/${newName}/g", $tmpPath]


I have tried various different combinations of this (i.e.

["/usr/bin/sed","-i''", "s/${fileName}/${newName}/g", $tmpPath]


["/usr/bin/sed","-i", '\'\', "s/${fileName}/${newName}/g", $tmpPath]


["/usr/bin/sed","-i", '\'\', '-e', "s/${fileName}/${newName}/g", $tmpPath]


However each time I run this, it creates ria & ria''.
I don't want the second file, ria''.

Can this not be accomplished? Or is there some other editor I can use? I don't want to install anything (i.e. gsed) on my mac.

I am running it as
system(@command);
.

Answer

What sed -i '' ... does is to pass "-i" as an argument, followed by a zero-length argument (the empty quotes). The single-quotes are not part of the argument, they're just there to indicate that there is an argument (it just doesn't have any content). To do the same thing in perl with system, use:

["/usr/bin/sed", "-i", "",  "s/${fileName}/${newName}/g", $tmpPath]