Searching multiple patterns (words) with ack?

前端 未结 4 1292
臣服心动
臣服心动 2021-01-02 03:39

I want to search multiple patterns in a directory containing recursive directories and files.

I know command for

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 03:43

    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.

提交回复
热议问题