linux - 使用 ack 搜索多个模式(单词)?

标签 linux grep ack ag

我想在包含递归目录文件目录中搜索多个模式

我知道 grep 命令如下

grep -e '(pattern1)|(pattern2)'

grep -r -E  'string1|string2|string3' /var/www/http

使用 ackag 的命令是什么?

最佳答案

这应该足够了:

ack -R 'string1|string2'

因为 -R 是默认的,你可以省略它:

ack 'string1|string2'

来自 man ack:

-r, -R, --recurse

Recurse into sub-directories. This is the default and just here for compatibility with grep. You can also use it for turning --no-recurse off.


如果你想从文件中获取模式,比如/path/to/patterns.file,你可以使用:

ack "$(cat /path/to/patterns.file)"

或等价地:

ack "$(< /path/to/patterns.file)"

我找不到与 grep -f 完全相同的词。

关于linux - 使用 ack 搜索多个模式(单词)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26275582/

相关文章:

python - ImportError : No module named tensorflow, 但tensorflow确实存在

linux - 如何使用 grep 和 sed 打印多个字符串?

linux - 我怎样才能得到返回结果?

regex - 使用ack或awk或比grep更好的方法从另一个文件中获取模式?

filenames - ack可以仅根据文件名查找文件吗?

c++ - 在 64 位系统上创建非常大的数组有什么缺点?

c - *nix 中 open 系统调用有什么用

linux - 在 Linux 中使用 shell 脚本从当前目录中的文件递归搜索和提取子字符串?

grep (BSD grep) 2.5.1-FreeBSD on mac os 10.8 行正则表达式模式不适用于重叠模式

bash - 使用 grep 读取行