How can I search for a multiline pattern in a file?

后端 未结 11 1102
陌清茗
陌清茗 2020-11-22 14:59

I needed to find all the files that contained a specific string pattern. The first solution that comes to mind is using find piped with xargs grep:

11条回答
  •  无人及你
    2020-11-22 15:57

    Using ex/vi editor and globstar option (syntax similar to awk and sed):

    ex +"/string1/,/string3/p" -R -scq! file.txt
    

    where aaa is your starting point, and bbb is your ending text.

    To search recursively, try:

    ex +"/aaa/,/bbb/p" -scq! **/*.py
    

    Note: To enable ** syntax, run shopt -s globstar (Bash 4 or zsh).

提交回复
热议问题