Chinaunix
标题:
删除C语言中的所有注释
[打印本页]
作者:
lmx07
时间:
2012-10-15 14:48
标题:
删除C语言中的所有注释
rt。
我找到了下面的shell脚本,确实可以实现。
#!/bin/sh -f
function del_comment_file()
{
#C++模式注释的删除。
#Delete the line begins with //
#首先删除//在行首的行
sed -i '/^[ \t]*\/\//d' $file
#Delete the line ends with //
#注意已经除去了 //在行首的情况,下面匹配除去URL的//部分,因为代码中有一部分中有
#URL,形如fun("ftp://")
sed -i 's/\/\/[^"]*//' $file
#删除以C语言中注释只在一行的行
sed -i 's/\/\*.*\*\///' $file
#Delete the lines between /* and */
#删除C语言中注释跨行的情况
sed -i '/^[ \t]*\/\*/,/.*\*\//d' $file
}
function del_comment()
求解释:
#Delete the lines between /* and */
#删除C语言中注释跨行的情况
sed -i '/^[ \t]*\/\*/,/.*\*\//d' $file
/, 代表什么意思?
作者:
dn833
时间:
2012-10-15 15:28
seq 10|sed '/3/,/5/d'
复制代码
作者:
lmx07
时间:
2012-10-21 15:49
回复
2#
dn833
懂了,威武
作者:
L_kernel
时间:
2012-10-21 19:02
就是sed定位两个address区间,然后delete掉了。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2