I am using this sed command on Linux, to patch one file, and it works fine:
sed -i -r "s/(\tpublic function __call.*)/\1\n\t\treturn null;/" rb.php
But when I try this command on OS X, I am getting an error:
sed: 1: "s/(\tpublic function __ ...": \1 not defined in the RE
So, can anybody help me to make command that will work both on Linux and OS X?
By the way, I tried command like:
sed -i '' -r "s/(\tpublic function __call.*)/\1\n\t\treturn null;/" rb.php
but it doesn't work on Linux.
One way to make the GNU version of the SED to work on the Mac OS X, is to directly install the gnu-sed along with the default names which will assure you that you won't have to run different commands on both the operating systems.
SED is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits, SED works by making only one pass over the input(s), and is consequently more efficient.
You may have heard that Macintosh OSX is just Linux with a prettier interface. That's not actually true. But OSX is built in part on an open source Unix derivative called FreeBSD.
The SED command in Linux stands for Stream EDitor and is helpful for a myriad of frequently needed operations in text files and streams. Sed helps in operations like selecting the text, substituting text, modifying an original file, adding lines to text, or deleting lines from the text.
For the Mac OS X sed, use -E
instead of -r
to get EREs. Additionally, the GNU extensions aren't there, so you'll need literal characters instead of the \t
and \n
metacharacters.
Or just install GNU sed, of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With