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

后端 未结 11 1171
陌清茗
陌清茗 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:38

    Here is a more useful example:

    pcregrep -Mi "(.*\n){0,5}" afile.html
    

    It searches the title tag in a html file even if it spans up to 5 lines.

    Here is an example of unlimited lines:

    pcregrep -Mi "(?s).*" example.html 
    

提交回复
热议问题