Regex 多行搜索模式?

Regex 多行搜索模式?,regex,bash,shell,unix,grep,Regex,Bash,Shell,Unix,Grep,我试着在任何一行上找到一个3个单词的模式,中间有任何东西。目前,我以这种方式使用pcregrep(-m表示多行): 我得到了这个结果: ./testing/test.txt: let prep = "select string1, dog from cat", " where string2 = 1", " and string3 = ?", 这很好。然而,我希望这个模式在几个换行符上找到这3个字符串,而不仅仅是连续的。例如,我希望找

我试着在任何一行上找到一个3个单词的模式,中间有任何东西。目前,我以这种方式使用pcregrep(-m表示多行):

我得到了这个结果:

./testing/test.txt:   let prep = "select string1, dog from cat",
              " where string2 = 1",
              " and string3 = ?",
这很好。然而,我希望这个模式在几个换行符上找到这3个字符串,而不仅仅是连续的。例如,我希望找到以下结果:

./testing/test.txt:   let prep = "select string1, dog from cat",
              " where apple = 1",
              " and string2 = 2",
              " and grass = 8",
              " and string3 = ?",
现在我的模式与上面的结果不匹配是有道理的,因为它只寻找一条换行符。因此,我认为将代码更改为这种方式可以解决这个问题(更改$sep变量并在搜索模式中添加星号):

但现在,这不会产生任何结果。将星号放在括号内也不会产生任何结果。所以我仍然在寻找一种模式,它允许在我的3个字符串之间有0个或更多的字符,包括换行符

find . -name "$FILE" 2>/dev/null -execdir \
sh -c "grep -aA999999 string1 '"{}"' | grep -aA999999 string2 | grep -q string3" \
';' -print
限制在string1、string2和string3之间的999999行


使用awk,不要在
\

后面加空格,这样可以做得更好。如果您知道如何使用awk,我愿意使用。这些多行字符串之间会有空行吗?
sep=$( echo ".|\n" )

find . -name "$FILE" 2>null | xargs pcregrep -M "string1($sep)*string2($sep)*string3" >> $grep_out
find . -name "$FILE" 2>/dev/null -execdir \
sh -c "grep -aA999999 string1 '"{}"' | grep -aA999999 string2 | grep -q string3" \
';' -print