Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos grep with-f选项根据模式文件的顺序返回不同的结果_Macos_Grep_Gnu - Fatal编程技术网

Macos grep with-f选项根据模式文件的顺序返回不同的结果

Macos grep with-f选项根据模式文件的顺序返回不同的结果,macos,grep,gnu,Macos,Grep,Gnu,我试图从另一个文件中的文本中匹配一个文件中列出的关键字。关键字文件以新行分隔 grep根据关键字的顺序(而不是输入文件)返回不同的结果 这里有一个例子 有了这个输入 # input.txt TRITONS, sea-deities; they sung the marriage chorus of ACHILLES. 案例1 # terms.txt ACHILLES TRITONS # grep returns just one match grep -o -f terms.txt inpu

我试图从另一个文件中的文本中匹配一个文件中列出的关键字。关键字文件以新行分隔

grep
根据关键字的顺序(而不是输入文件)返回不同的结果

这里有一个例子

有了这个输入

# input.txt
TRITONS, sea-deities; they sung the marriage chorus of ACHILLES.
案例1

# terms.txt
ACHILLES
TRITONS

# grep returns just one match
grep -o -f terms.txt input.txt  
ACHILLES
案例2:我刚刚更改了关键字文件的顺序

# terms.txt
TRITONS
ACHILLES

# grep returns both matches ! 
grep -o -f terms.txt input.txt 
TRITONS
ACHILLES

试图理解这种行为。

我在
grep(BSD grep)2.5.1-FreeBSD
中发现了这个问题(这是Mac High Sierra上提供的默认版本)

改为使用
Gnu Grep ggrep(Gnu Grep)3.4.
进行修复

通过
brew安装grep
安装


请注意,这个版本的grep现在被称为
ggrep

您没有在任何地方使用
input.txt
。已更新。我无法用GNU grep 3.4复制此内容-我使用Mac
grep(BSD grep)2.5.1-FreeBSD
附带的两个版本的
terms.txt
获得两个匹配项。我将尝试GNU grep。是的,这在GNU grep
ggrep(GNU grep)3.4中是不可复制的。无论顺序如何,此版本都会找到这两个术语。谢谢