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.
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'
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.