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


i needed find files contained specific string pattern. first solution comes mind using find piped xargs grep:

find . -iname '*.py' | xargs grep -e 'your_pattern' 

but if need find patterns spans on more 1 line, i'm stuck because vanilla grep can't find multiline patterns.

so discovered pcregrep stands perl compatible regular expressions grep.

for example, need find files '_name' variable immediatelly followed '_description' variable:

find . -iname '*.py' | xargs pcregrep -m '_name.*\n.*_description' 

tip: need include line break character in pattern. depending on platform, '\n', \r', '\r\n', ...


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -