3 added 152 characters in body
source | link
$ pcregrep -Mo 'pin\(ABC\) (\{([^{}]++|(?1))*\})' file
pin(ABC) {
              a b c d e f {
              abc
              }
             }

If you don't have pcregrep but have GNU grep and it has been built with support for PCRE patterns and your file is not too big and doesn't contain NUL characters, you can do:

grep -zPo 'pin\(ABC\) (\{([^{}]++|(?1))*\})' file

Those (pcregrep and grep -P) are using PCRE patterns that support recursive regex operators.

pcregrep -M turns on the multiline mode (where pcregrep can pull several lines as needed while matching the regexp) and grep -z tells the records are NUL-separated instead of being lines.

The trick above is in the (?1) operator that means the regexps inside the first paren group so we have a recursive regexp: we're matching { followed by a sequence of 0 or more (*) sequences of non-brace characters ([^{}]++, ++ being the possessive version of +) or the regexp in the outer (...) again ({ followed by...).

See the man page for pcrepattern for details. That's copied almost verbatim from an example in there.

Using perl:

perl -l -0777 -ne 'print $& while /pin\(ABC\) (\{([^{}]++|(?1))*\})/g'

(like for grep it slurps the whole file in memory).

$ pcregrep -Mo 'pin\(ABC\) (\{([^{}]++|(?1))*\})' file
pin(ABC) {
              a b c d e f {
              abc
              }
             }

If you don't have pcregrep but have GNU grep and it has been built with support for PCRE patterns and your file is not too big and doesn't contain NUL characters, you can do:

grep -zPo 'pin\(ABC\) (\{([^{}]++|(?1))*\})' file

Those (pcregrep and grep -P) are using PCRE patterns that support recursive regex operators.

pcregrep -M turns on the multiline mode (where pcregrep can pull several lines as needed while matching the regexp) and grep -z tells the records are NUL-separated instead of being lines.

The trick above is in the (?1) operator that means the regexps inside the first paren group so we have a recursive regexp: we're matching { followed by a sequence of 0 or more (*) sequences of non-brace characters ([^{}]++, ++ being the possessive version of +) or the regexp in the outer (...) again ({ followed by...).

See the man page for pcrepattern for details. That's copied almost verbatim from an example in there.

$ pcregrep -Mo 'pin\(ABC\) (\{([^{}]++|(?1))*\})' file
pin(ABC) {
              a b c d e f {
              abc
              }
             }

If you don't have pcregrep but have GNU grep and it has been built with support for PCRE patterns and your file is not too big and doesn't contain NUL characters, you can do:

grep -zPo 'pin\(ABC\) (\{([^{}]++|(?1))*\})' file

Those (pcregrep and grep -P) are using PCRE patterns that support recursive regex operators.

pcregrep -M turns on the multiline mode (where pcregrep can pull several lines as needed while matching the regexp) and grep -z tells the records are NUL-separated instead of being lines.

The trick above is in the (?1) operator that means the regexps inside the first paren group so we have a recursive regexp: we're matching { followed by a sequence of 0 or more (*) sequences of non-brace characters ([^{}]++, ++ being the possessive version of +) or the regexp in the outer (...) again ({ followed by...).

See the man page for pcrepattern for details. That's copied almost verbatim from an example in there.

Using perl:

perl -l -0777 -ne 'print $& while /pin\(ABC\) (\{([^{}]++|(?1))*\})/g'

(like for grep it slurps the whole file in memory).

2 added 700 characters in body
source | link
$ pcregrep -Mo '(?s)pin\'pin\(ABC\) (\{([^{}]++|(?1))*\})' file
pin(ABC) {
              a b c d e f {
              abc
              }
             }

If you don't have pcregrep but have GNU grep and it has been built with support for PCRE patterns and your file is not too big and doesn't contain NUL characters, you can do:

grep -zPo '(?s)pin\'pin\(ABC\) (\{([^{}]++|(?1))*\})' file

Those (pcregrep and grep -P) are using PCRE patterns that support recursive regex operators.

pcregrep -M turns on the multiline mode (where pcregrep can pull several lines as needed while matching the regexp) and grep -z tells the records are NUL-separated instead of being lines.

The trick above is in the (?1) operator that means the regexps inside the first paren group so we have a recursive regexp: we're matching { followed by a sequence of 0 or more (*) sequences of non-brace characters ([^{}]++, ++ being the possessive version of +) or the regexp in the outer (...) again ({ followed by...).

See the man page for pcrepattern for details. That's copied almost verbatim from an example in there.

$ pcregrep -Mo '(?s)pin\(ABC\) (\{([^{}]++|(?1))*\})' file
pin(ABC) {
              a b c d e f {
              abc
              }
             }

If you don't have pcregrep but have GNU grep and it has been built with support for PCRE patterns and your file is not too big and doesn't contain NUL characters, you can do:

grep -zPo '(?s)pin\(ABC\) (\{([^{}]++|(?1))*\})' file

See the man page for pcrepattern for details.

$ pcregrep -Mo 'pin\(ABC\) (\{([^{}]++|(?1))*\})' file
pin(ABC) {
              a b c d e f {
              abc
              }
             }

If you don't have pcregrep but have GNU grep and it has been built with support for PCRE patterns and your file is not too big and doesn't contain NUL characters, you can do:

grep -zPo 'pin\(ABC\) (\{([^{}]++|(?1))*\})' file

Those (pcregrep and grep -P) are using PCRE patterns that support recursive regex operators.

pcregrep -M turns on the multiline mode (where pcregrep can pull several lines as needed while matching the regexp) and grep -z tells the records are NUL-separated instead of being lines.

The trick above is in the (?1) operator that means the regexps inside the first paren group so we have a recursive regexp: we're matching { followed by a sequence of 0 or more (*) sequences of non-brace characters ([^{}]++, ++ being the possessive version of +) or the regexp in the outer (...) again ({ followed by...).

See the man page for pcrepattern for details. That's copied almost verbatim from an example in there.

1
source | link

$ pcregrep -Mo '(?s)pin\(ABC\) (\{([^{}]++|(?1))*\})' file
pin(ABC) {
              a b c d e f {
              abc
              }
             }

If you don't have pcregrep but have GNU grep and it has been built with support for PCRE patterns and your file is not too big and doesn't contain NUL characters, you can do:

grep -zPo '(?s)pin\(ABC\) (\{([^{}]++|(?1))*\})' file

See the man page for pcrepattern for details.