I want to search multiple patterns
in a directory
containing recursive directories
and files
.
I know command for grep
which is as follows
grep -e '(pattern1)|(pattern2)'
or
grep -r -E 'string1|string2|string3' /var/www/http
What is the command for that using ack
or ag
?
For
ag
, as of verion 0.19.2 the default is to search in directories and files recursively.To search for multiple patterns, you can use similiar syntax as
ack
will search for both
pattern1
andpattern2
.In case you don't want to search recursively, you can set the search depth to 1 by the switch
--depth NUM
Therefore,
will only search in the current directory for both patterns.
This should be enough:
As
-R
is the default, you can omit it:From
man ack
:If you want to get the pattern from a file, say /path/to/patterns.file, you can use:
or equivallently:
I cannot find an exact equivalent to
grep -f
.I don't know why but for my use case, the pipe solution didn't work.
I simply used the output of
ack -l
as the input to grep. For example, to quickly find all Javascript files containingstring 1
andstring 2
: