Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5741369
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类:

2006-06-11 12:53:04

很早的时候,写的一个脚本,今天拿出来修改了一下。

代码:
#!/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()
{
#$Dir=`pwd`

for file in `ls`;do
case $file in
*.c )
del_comment_file
;;
*.cpp )
del_comment_file
;;
*.h )
del_comment_file
;;
* )
if [ -d $file ];then
cd $file
del_comment
cd ..
fi
;;
esac
done
}


Dir=$1

if [ ! -e $Dir ];then
echo "The Directory isn't exist."
exit
fi

cd $Dir

del_comment

直接给脚本一个目录,它就会把目录下的C++文件的注释删除。


阅读(3491) | 评论(11) | 转发(0) |
0

上一篇:xargs的中文man

下一篇:批量添加samba账户

给主人留下些什么吧!~~

xiaolixi2020-01-13 18:29:51

老师您好,请问sed -i \'/^[ \\t]*\\/\\*/,/.*\\*\\//d\' $file
这个表达式中/,/.*有什么作用啊?