【发布时间】:2016-06-03 08:04:11
【问题描述】:
我有这个在 OS X 10.6.8 (Snow Leopard) 中运行良好的命令字符串(它告诉我它的 grep 是 grep (GNU grep) 2.5.1)...
$ grep -hi 'TERM' file1.txt | cut -d '|' -f 3 | grep -f - file2.txt
(在 file1 中查找所有包含 TERM 的行,将每一行缩减为字段 3 中的唯一 ID 号,然后在 file2 中查找这些 ID)
然而这在 OS X 10.11.5 (El Capitan) 中失败了(它告诉我它的 grep 是 grep (BSD grep) 2.5.1-FreeBSD)...
grep: -: No such file or directory
我真的不想在这台机器上安装 GNU grep。有没有办法修复第二个 grep 命令,以便 BSD grep 可以工作?或者一般来说有更好的方法?
一些示例代码:
file1.txt 看起来像:
Jones Inc||000123||foo||bar
TerminatorLLC||000124||foo||bar
Conan LP||000125||foo||bar
Termites-R-Us||000126||foo||bar
file2.txt 类似:
000123||210 Main Street||moo||car
000124||Los Angeles||moo||car
000125||Mythical Kingdom||moo||car
000126||Your Woodwork||moo||car
【问题讨论】: