grep - 奇怪的行为 grep -rnw
问题描述
我在 MacOS 中使用 grep (BSD grep) 2.5.1-FreeBSD,我发现了以下行为。
我有两个 *.tex 文件。每一个都包含以下几行
$k$-th bit of
$(i-m)$-th bit of
分别。当我跑
grep --color -rnw . -e '\$-th bit of' --include="*.tex"
我只得到了第二个文件,即 $(im)$-th 位,而我期望这两行。你能帮我理解这种行为吗?
解决方案
永远不要使用-r
or--include
或任何其他 grep 选项来查找文件。find
当有一个非常好的工具用于查找文件时,GNU 家伙真的把这些选项添加到 grep 中搞砸了,现在他们已经将 grep 变成了查找文件和全局匹配文件中的正则表达式并打印结果( G/RE/P
)。
保持简单 -使用g/re/p找到文件,find
然后使用:grep
find . -name '*.tex' -exec grep --color -n '\$-th bit of' {} +
正如其他人指出的那样,您的g/re/p
问题是-w
arg 所以我在上面删除了它。
推荐阅读
- python - 抓取 Div 类 HTML 时如何在 For 循环中嵌套 If 语句
- php - 即使使用“代理授权:基本”,PHP 也无法使用代理进行身份验证
- mysql - 我有可能找到一行包含一个字符串吗?假设我不知道哪些列包含字符串
- php - in_array 的选项值不起作用
- c# - DbContext 在使用异步任务方法时被释放
- sql - PL/SQL [忽略 SQL 语句]
- python - 我应该如何在线性回归中拟合我的曲线?:张量流
- apache-kafka - kafka Burrow 报告相同 consumer_group 和相同主题的多个偏移量
- marklogic - 使用数据中心中的文档值进行选择性协调
- c++ - 这个 C++ 宏有什么作用(竞争性编程)?