[英]What is a grep pattern for matching lines?
我試圖在我的測試套件中找到所有使用單行it
方法的案例。 基本上,我正在尋找具有以下行的文件:
it { expect(some_stuff).to be_true }
it { expect(other_stuff).to be_false }
但不是這個:
it { expect(some_stuff).to be_true }
# a bunch of other stuff
it { expect(other_stuff).to be_true }
並且無法完全弄清楚模式。 我努力了:
> grep it.\{*\}\n*it ./test/directory -lR
# and
> grep it.\{*\}\n*it.\{*
它什么都不返回,但我知道至少有一個匹配的文件。 有誰知道如何創建我正在尋找的模式?
您可能正在尋找的模式是/(?:it.*$)\n(?:it.*$)/
但是您可能在使用grep
或egrep
時遇到的問題是,此實用程序一次只搜索一行文件,因此它不支持在正則表達式中使用\n
。
因此,您可能想尋找除grep
之外的其他選項。
grep手冊頁了解更多信息。
您可以使用pcgregrep :
pcregrep -lr -M "it.{.*}\nit" ./test/directory
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.