sed or awk multiline replace
I am trying to append formatting to all /* TODO : ... */ tags, but I am having trouble in the multi-line area. I can do single line sed's; but for multiline sed and awk, I don't know.
How do I do this? I开发者_运维技巧'm open to either. Here's what I have so far.
sed 's/\/\/\*[ \t]*TODO[ \t]*:.*/*\//<span style="color:#aaaaaa;font-weight:bold;">&</span>/g'
replace :
int void main ( int h, char * argv[] )
int a, b; /* TODO :
- include libraries
...
*/
foobar();
/* TODO : fix missing {'s */
with :
int void main ( int h, char * argv[] )
int a, b; <span style="color:#aaaaaa; font-weight:bold;">/* TODO :
- include libraries
...
*/</span>
foobar();
<span style="color:#aaaaaa; font-weight:bold;">/* TODO : fix missing {'s */ </span>
gawk 'BEGIN{
RS="*/"
replace="<span style=\"color:#aaaaaa; font-weight:bold;\">"
}
/\/\* +TODO/{
gsub(/\/\* +TODO/,replace" /* TODO")
RT=RT "</span>"
}
{ print $0RT}
' file
output
$ ./shell.sh
int void main ( int h, char * argv[] )
int a, b; <span style="color:#aaaaaa; font-weight:bold;"> /* TODO :
- include libraries
...
*/</span>
foobar();
<span style="color:#aaaaaa; font-weight:bold;"> /* TODO : fix missing {'s */</span>
精彩评论