使用Grep查找两个短语之间的文本块(包括短语) [英] Use Grep to find blocks of text between two phrases (including the phrases)

查看:644
本文介绍了使用Grep查找两个短语之间的文本块(包括短语)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用grep来读取所有以文本开头的文本:

  mutablePath = CGPathCreateMutable(); 

结尾为:

  CGPathAddPath(skinMutablePath,NULL,mutablePath); 

如果在这两个短语之间有任意数量的文字?

注意:我必须使用grep,因为我使用的是BBEdit。

解决方案

使用 GNU grep

  grep -oPz'mutablePath = CGPathCreateMutable\\ \\(\);。*?(\ n。*?)*。*?CGPathAddPath \(skinMutablePath,NULL,mutablePath \);'file 

如果您没有 GNU grep ,您可以使用 pcregrep 来实现同样的功能:

  pcregrep -M'mutablePath = CGPathCreateMutable\(\);。* (\\\
|。)* CGPathAddPath \(skinMutablePath,NULL,mutablePath \);'file


Is it possible to use grep to high lite all of the text starting with:

mutablePath = CGPathCreateMutable();

and ending with:

CGPathAddPath(skinMutablePath, NULL, mutablePath);

Where there is an arbitary amount of text in between those two phrases?

NOTE: I have to use grep because I'm using BBEdit.

解决方案

You will need to use GNU grep:

grep -oPz 'mutablePath = CGPathCreateMutable\(\);.*?(\n.*?)*.*?CGPathAddPath\(skinMutablePath, NULL, mutablePath\);' file

If you don't have GNU grep, you could use pcregrep to achieve the same thing:

pcregrep -M 'mutablePath = CGPathCreateMutable\(\);.*(\n|.)*CGPathAddPath\(skinMutablePath, NULL, mutablePath\);' file

这篇关于使用Grep查找两个短语之间的文本块(包括短语)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆