如何使用GNU SED在Mac OS X [英] How to use GNU sed on Mac OS X

查看:917
本文介绍了如何使用GNU SED在Mac OS X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS 10.10.3,我安装GNU-sed的键入:

Under Mac OS 10.10.3, I installed gnu-sed by typing:

brew install gnu-sed --default-names

当我再次键入它,我得到的消息:

When I type it again, I get the message:

GNU-sed的-4.2.2已经安装

gnu-sed-4.2.2 already installed

然而,即使重新启动系统并重新启动终端后,我仍然无法使用的SED GNU版本。例如:

However, even after rebooting the system and restarting Terminal, I still cannot use the GNU version of sed. For example:

echo a | sed ’s_A_X_i’

收益:
糟糕的标志替换命令我

returns: bad flag in substitution command 'i'

我应该怎么做才能GNU版本的工作?
以下是我的$ PATH变量的路径。

What should I do to get the GNU version working? Here are the paths in my $PATH variable.

/Users/WN/-myUnix
/opt/local/bin
/opt/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/Applications/calibre.app/Contents/MacOS
/opt/ImageMagick/bin
/usr/texbin 

我很抱歉,如果我的问题似乎是显而易见的,但我对我自己的学习shell脚本和UNIX程序的安装方式不太明白呢。任何帮助使用GNU兼容的命令(在这种情况下sed的,但很快我需要其​​他人也)在我的Mac,而不会造成损坏或不必要的混乱会大大AP preciated。

I'm sorry if my question seems obvious, but I am learning shell scripting on my own and don't quite understand yet how UNIX programs are installed. Any help to use GNU compliant commands (in this case sed, but soon I'll need others as well) on my Mac without causing damage or unnecessary clutter would be greatly appreciated.

推荐答案

您已经拥有了GNU-sed的无安装 - 与 - 默认名称选项。有了它安装的 SED 的/ usr / local / bin目录/ ,而不该该选项选项​​它安装的 gsed

You already have the gnu-sed installed without the --with-default-names option. With that option it installs sed to /usr/local/bin/, without that option it installs gsed.

所以,你得什么做的是:

So what you gotta do is:

$ brew uninstall gnu-sed
$ brew install gnu-sed --with-default-names

更新路径,如果需要的...

Update path if needed...

$ echo $PATH | grep -q '/usr/local/bin'; [ $? -ne 0 ] && export PATH=/usr/local/bin:$PATH
$ echo a | sed ’s_A_X_i’

或使用 gsed 正如其他建议。

or use gsed as others suggested.

这篇关于如何使用GNU SED在Mac OS X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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