删除 C语言注释
发表于 : 2011-11-06 23:34
假设有一组C语言文件,这些文件开头都有几行注释。注释内容的第一行行首有/*,注释结束行只有*/没有其它内容。编写一个脚本,删除这些注释。
我是这样写的:
大家有更好的方法吗?求指导。
我是这样写的:
代码: 全选
#!/bin/sh
for file in "$@" ; do
begin=`grep -nm1 '/\*' $file | cut -d':' -f1`
end=`grep -nm1 '\*/' $file | cut -d':' -f1`
sed -n $begin,$end'!p' $file
done