Jee*_*tel 2 c linux shell comments
任何可用于将c99样式注释//转换为c样式注释/* ..*/到整个项目的工具/脚本?
如果我有这样的代码
// printf("stcakoverflow");
Run Code Online (Sandbox Code Playgroud)
然后它将被转换为
/* printf("stcakoverflow"); */
Run Code Online (Sandbox Code Playgroud)
并且
int temp // this is temp varialbe
Run Code Online (Sandbox Code Playgroud)
转换成
int temp /* this is temp varialbe */
Run Code Online (Sandbox Code Playgroud)
对于命令行示例,请尝试以下内容:
echo "int temp; // this is temp variable" | sed 's@//\(.*\)$@/*\1 */@'
Run Code Online (Sandbox Code Playgroud)
以上结果
int temp; /* this is temp variable */
对于一个真实的文件,你可以使用,例如cat代替echo,它是管道sed和sed执行"魔术" 的命令.
编辑:如何为大量文件执行此操作
这样的事情可能是:
cd /your/source/directory
mkdir converted-files
for f in *.cpp; do
cat $f | sed 's@//\(.*\)$@/*\1 */@' > converted-files/$f
done
Run Code Online (Sandbox Code Playgroud)
现在所有转换后的源文件都将在一个文件夹中converted-files.
对于使用IDE /编辑器的人来说,使用Notepad ++(你也可以在Linux上使用Wine运行它)正则表达式匹配并替换你可以为一堆文件做.
找到什么: //(.*?)$
替换为:/\*\1\*/
