我正在尝试将格式化添加到所有/ * TODO:... * /标签,但我在多行区域遇到问题。我可以做单线sed;但对于多线sed和awk,我不知道。
我该怎么做?我愿意接受。 这是我到目前为止所拥有的。
sed 's/\/\/\*[ \t]*TODO[ \t]*:.*/*\//<span style="color:#aaaaaa;font-weight:bold;">&</span>/g'
替换:
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>
答案 0 :(得分:4)
gawk 'BEGIN{
RS="*/"
replace="<span style=\"color:#aaaaaa; font-weight:bold;\">"
}
/\/\* +TODO/{
gsub(/\/\* +TODO/,replace" /* TODO")
RT=RT "</span>"
}
{ print $0RT}
' file
输出
$ ./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>