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

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

    You can use the grep alternative sift here (disclaimer: I am the author).

    It support multiline matching and limiting the search to specific file types out of the box:

    sift -m --files '*.py' 'YOUR_PATTERN'

    (search all *.py files for the specified multiline regex pattern)

    It is available for all major operating systems. Take a look at the samples page to see how it can be used to to extract multiline values from an XML file.

提交回复
热议问题