用ack搜索多个模式(单词)? [英] Searching multiple patterns (words) with ack?
问题描述
我想在目录
中搜索多个模式
,其中包含递归目录
和 files
。
我知道 grep $ c
grep -e'(pattern1)|(pattern2)'
或
grep -r -E'string1 | string2 | string3'/ var / www / http
这个命令是什么使用 ack
或 ag
?
$ b
ack -R'string1 | string2'
由于 -R
是默认值,所以您可以忽略它:
ack'string1 | string2'
从 man ack
:
-r , -R ,--recurse
递归到子目录。这是默认值,只是在这里
p>如果你想从文件中获取模式,比如/path/to/patterns.file,你可以使用:
与grep兼容。 b
ack$(cat /path/to/patterns.file)
或等价: p>
ack$(< /path/to/patterns.file)
我无法找到与
grep -f
完全等价的内容。I want to search multiple
patterns
in adirectory
containingrecursive directories
andfiles
.I know command for
grep
which is as followsgrep -e '(pattern1)|(pattern2)'
or
grep -r -E 'string1|string2|string3' /var/www/http
What is the command for that using
ack
orag
?解决方案This should be enough:
ack -R 'string1|string2'
As
-R
is the default, you can omit it:ack 'string1|string2'
From
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.
If you want to get the pattern from a file, say /path/to/patterns.file, you can use:
ack "$(cat /path/to/patterns.file)"
or equivallently:
ack "$(< /path/to/patterns.file)"
I cannot find an exact equivalent to
grep -f
.这篇关于用ack搜索多个模式(单词)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!