Sed命令在Linux上有效,但在OS X上无效 [英] Sed command works on Linux, but not on OS X

查看:118
本文介绍了Sed命令在Linux上有效,但在OS X上无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux上使用此sed命令来修补一个文件,并且工作正常:

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

但是当我在OS X上尝试此命令时,出现错误:

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

那么,有人可以帮助我做出在Linux和OS X上都可以使用的命令吗?

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

但它在Linux上不起作用.

but it doesn't work on Linux.

推荐答案

对于Mac OS X sed,请使用-E而不是-r来获取ERE.此外,还不存在GNU扩展,因此您需要文字字符而不是\t\n元字符.

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.

或者当然也可以安装GNU sed.

Or just install GNU sed, of course.

这篇关于Sed命令在Linux上有效,但在OS X上无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆