3

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.

anubhava
  • 664,788
  • 59
  • 469
  • 547
Ser Pounce
  • 13,548
  • 14
  • 76
  • 162

3 Answers3

3

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
Steve
  • 41,445
  • 12
  • 83
  • 96
0

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.

anubhava
  • 664,788
  • 59
  • 469
  • 547
0

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

perl -ne '/start line/ .. /end line/ and print'
Qtax
  • 31,392
  • 7
  • 73
  • 111