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

后端 未结 11 1106
陌清茗
陌清茗 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条回答
  •  萌比男神i
    2020-11-22 15:57

    grep -P also uses libpcre, but is much more widely installed. To find a complete title section of an html document, even if it spans multiple lines, you can use this:

    grep -P '(?s).*' example.html
    

    Since the PCRE project implements to the perl standard, use the perl documentation for reference:

    • http://perldoc.perl.org/perlre.html#Modifiers
    • http://perldoc.perl.org/perlre.html#Extended-Patterns

提交回复
热议问题