0

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);.

Ria
  • 447
  • 6
  • 16
  • Possible duplicate of [In-place edits with sed on OS X](http://stackoverflow.com/questions/7573368/in-place-edits-with-sed-on-os-x) – Sundeep Nov 14 '16 at 01:41

1 Answers1

1

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]
Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151