grep 在 OSX 上的工作方式不同吗 [英] Does grep work differently on OSX

查看:23
本文介绍了grep 在 OSX 上的工作方式不同吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像以前在 Linux 中使用的那样使用 grep,它具有所有惊人的功能和 RegEx 的所有功能,...但在 Mac OS X 上它没有按我预期的那样工作.

I am trying to use grep like I am used to from Linux, with all its amazing features and all the power from RegEx,... but on Mac OS X it's not working as I expect.

如果我使用-P"(Perl Regex),它会给我用法"(--help)输出.在那里,我们在参数-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ"列表中找到了-P"参数...还是不行.

If I use "-P" (Perl Regex) it gives me the "usage" (--help) output. In there we find the "-P" parameter in the list of parameters "-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ"... Still not working.

另一个例子是星号或加号.我正在尝试这个 http://wiki.bash-hackers.org/howto/conffile

Another example is the asterisk or the plus sign. I am trying this http://wiki.bash-hackers.org/howto/conffile

检查配置文件中指令使用的不当内容:

To check a config file for inappropriate content that instruction uses:

if egrep -q -v '^#|^[^ ]*=[^;]*' "$configfile"; then
  echo "Config file is unclean, cleaning it..." >&2
  # filter the original to a new file
  egrep '^#|^[^ ]*=[^;&]*'  "$configfile" > "$configfile_secured"
  configfile="$configfile_secured"
fi

它在这样的行上不起作用:

And it does not work on lines like this:

DATABASE=some_database; ls -la

我做错了什么?因为所有这些都可以在 Linux 机器上正常工作.

What am I doing wrong? Cause all of this works just fine on Linux machines.

推荐答案

在 OS X 上你默认有 FreeBSD grep,在 Linux 上通常是 GNU grep.

On OS X you have FreeBSD grep by default, on Linux usually GNU grep.

以下资源可以解释为什么 GNU grep 似乎更好(更快):

The following resources may explain why GNU grep seems to be better (and faster):

这篇关于grep 在 OSX 上的工作方式不同吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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