Question

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.

Was it helpful?

Solution

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

OTHER TIPS

If you want to print the lines between and including these you could use:

perl -ne '/start line/ .. /end line/ and print'

You can use sed instead like this:

sed -n '/mutablePath = CGPathCreateMutable();/,/CGPathAddPath(skinMutablePath, NULL, mutablePath);/p' infile

EDIT:

Not sure if -P flag of grep is supported in BBEdit. If it is then you can use this:

grep -oP 'mutablePath = CGPathCreateMutable();\X*CGPathAddPath(skinMutablePath, NULL, mutablePath);/' infile

As per grep man page:

-P, --perl-regexp Interpret PATTERN as a Perl regular expression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top