views:

33

answers:

2

How can I iterate over multi-line regexp matches using sed and bash? I'm trying to generate some quick docs from comments in a file, like so:

/**
 * @name myFun
 * @return {int}
 */

I can extract every comment block using sed -n -e '/\/\*\*$/,/\*\/$/p', but now I'd like to stuff each match into a bash array so I can parse the details later. Thanks.

A: 

I think you'd probably be better off using Doxygen.

By the way, your sed command might be more readable using alternate delimiters:

sed -n -e '\|/\*\*$|,\|\*/$|p'
Dennis Williamson
A: 

I think I would be looking to a scripting tool - I'd reach for Perl, but Python can probably handle it too. I'd probably slurp the entire source file, then use a multi-line regex to pick up the comments.

The reason for not trying it in sed plus bash is that sed would output N-line comments, which you'd then have to split - and that would be tricky.

Jonathan Leffler