开发者

Iterating Over Regexp Matches with Sed and Bash?

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 a开发者_JS百科rray so I can parse the details later. Thanks.


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.


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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜