Grep the whole body of a function

Posted by dotancohen on Super User See other posts from Super User or by dotancohen
Published on 2012-11-27T22:34:29Z Indexed on 2012/11/27 23:12 UTC
Read the original article Hit count: 283

Filed under:
|
|
|

Supposing I know that someFile.php contains the definition for someFunction(). How would I go about displaying the whole body of the function in stdout? If I know that the body is 10 lines long then I would use cat someFile.php | grep -A 10 "function someFunction" [1] but in reality the function could be any arbitrary length.

I figured that with sed I could use Vimesque commands such as /function someFunction<Return>/{<Return>% [2] but I can't figure out exactly how to format it. Ideally, the PHPDoc before the function would be output along with the function.

Any help or links to the appropriate fine manual would be appreciated. Thanks!

[1] I know that the cat is redundant, but I find this format easier to read.

[2] Find the function definition, go to the opening brace, go to the close brace

© Super User or respective owner

Related posts about bash

Related posts about vim