Grep regex 在排除关键字列表的同时查找重复的单词
Grep regex to find duplicate words while excluding a list of keywords
我在一个目录中有很多数据,我想找到任何不是数字的双字实例。我从 here:
开始
\b(\w+) \b
并将其扩展为在结果中包含我不想要的内容:
(?!(?:one|two|three|four|five|six|seven|eight|nine|oh|zero))\b(\w+) \b
当我将它作为 python 表达式放入 regex101 时(因为这是我所熟悉的),这有效,但当我在 grep 命令中使用它时无效。我意识到我不能使用 !,所以我在阅读 this question:
后尝试了这个
grep -Proh "\b(\w+) \b" | grep -Prohv "?(?:one|two|three|four|five|six|seven|eight|nine|oh|zero)"
其中 returns "grep: nothing to repeat"。我不确定我是否使用了正确的 grep 参数,或者我使用的正则表达式有什么问题。
要匹配的示例数据:
今天评估可能性。怀疑这种情况正在发生
要忽略的示例数据:
比重一点零零七
只需 -P
或 -oP
就足够了。
$ grep -P '(?!(?:one|two|three|four|five|six|seven|eight|nine|oh|zero))\b(\w+) \b' file
today to evaluate for possibilities. doubt that that is occurring
$ grep -oP '(?!(?:one|two|three|four|five|six|seven|eight|nine|oh|zero))\b(\w+) \b' file
that that
我在一个目录中有很多数据,我想找到任何不是数字的双字实例。我从 here:
开始\b(\w+) \b
并将其扩展为在结果中包含我不想要的内容:
(?!(?:one|two|three|four|five|six|seven|eight|nine|oh|zero))\b(\w+) \b
当我将它作为 python 表达式放入 regex101 时(因为这是我所熟悉的),这有效,但当我在 grep 命令中使用它时无效。我意识到我不能使用 !,所以我在阅读 this question:
后尝试了这个 grep -Proh "\b(\w+) \b" | grep -Prohv "?(?:one|two|three|four|five|six|seven|eight|nine|oh|zero)"
其中 returns "grep: nothing to repeat"。我不确定我是否使用了正确的 grep 参数,或者我使用的正则表达式有什么问题。
要匹配的示例数据:
今天评估可能性。怀疑这种情况正在发生
要忽略的示例数据:
比重一点零零七
只需 -P
或 -oP
就足够了。
$ grep -P '(?!(?:one|two|three|four|five|six|seven|eight|nine|oh|zero))\b(\w+) \b' file
today to evaluate for possibilities. doubt that that is occurring
$ grep -oP '(?!(?:one|two|three|four|five|six|seven|eight|nine|oh|zero))\b(\w+) \b' file
that that