我正在搜索文件中从第3行开始到第4行结束的模式,如何在linux中搜索这些模式
有文本的猫myfile.txt
you know who is super hero
where they are
super hero are born by birth,
they are good for us.
grep -irls'超级英雄是天生的,对我们有好处'*
答案 0 :(得分:1)
如果pcregrep
适用于您的系统,则易于使用:
pcregrep -M -irls 'super hero are born by birth,\nthey are good for us' *
-M
启用多行匹配。 \n
匹配换行符。
如果报价在任何时候都可能被分成多行,那么您可以将(恰好匹配一个空格)的每次出现都替换为
\s+
(匹配任何一个或多个匹配项) “空白”字符):
pcregrep -M -irls 'super\s+hero\s+are\s+born\s+by\s+birth,\s+they\s+are\s+good\s+for\s+us' *
答案 1 :(得分:0)
如果您有GNU grep,请尝试以下操作:
grep -zPirls 'super hero are born by birth,[[:space:]]*they are good for us' *
GNU awk:
awk -v RS='' '/super hero are born by birth,[[:space:]]*they are good for us/{print FILENAME}' *