awk或者sed多行更换 [英] sed or awk multiline replace
本文介绍了awk或者sed多行更换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图格式化追加到所有/ * TODO:... * /标签,但我有在多行区域的麻烦。我可以做一行SED的;但多行的sed和awk,我不知道。
我如何做到这一点?我打开任一。
这里是我到目前为止所。
SED的/ \\ / \\ / \\ * [\\ t] * TODO [\\ t] *:* / * \\ //<跨度风格=COLOR:# AAAAAA;字体重量:大胆;>&安培;< / SPAN&/克'
替换:
INT无效的主要(INT小时,字符*的argv [])
诠释A,B; /* 去做 :
- 包括库
...
* /
foobar的();
/ * TODO:修复丢失{'S * /
与
INT无效的主要(INT小时,字符*的argv [])
诠释A,B; <跨度风格=COLOR:#AAAAAA;字体重量:大胆;> / * TODO:
- 包括库
...
* /< / SPAN>
foobar的();
<跨度风格=COLOR:#AAAAAA;字体重量:大胆;> / * TODO:修复丢失{'S * /< / SPAN>
解决方案
的gawk'BEGIN {
RS =* /
取代=<跨度风格= \\COLOR:#AAAAAA;字体重量:大胆; \\>中
}
/ \\ / \\ * + TODO / {
GSUB(/ \\ / \\ * + TODO /替换/ * TODO)
RT =室温&下; /跨度>中
}
{$打印} 0RT
'文件
输出
$ ./shell.sh
INT无效的主要(INT小时,字符*的argv [])
诠释A,B; <跨度风格=COLOR:#AAAAAA;字体重量:大胆;> /* 去做 :
- 包括库
...
* /< / SPAN> foobar的();
<跨度风格=COLOR:#AAAAAA;字体重量:大胆;> / * TODO:修复丢失{'S * /< / SPAN>
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>
这篇关于awk或者sed多行更换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文