Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Grep to find blocks of text between two phrases (including the phrases)

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.

like image 986
Ser Pounce Avatar asked Dec 02 '25 15:12

Ser Pounce


1 Answers

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
like image 59
Steve Avatar answered Dec 04 '25 08:12

Steve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!