清除c语言代码中注释的shell脚本(sed)
时间:2014-12-05 02:41 来源:www.it.net.cn 作者:IT
写了一段shell脚本,用来清除c代码中的注释,不敢独享,分享给大伙。
运行示例:Run this script as follows:
cat file.c | ./script.sh
1,c代码示例
file.c:
#include<stdio.h>
/* This is a test program
* Version 1.0
* */
int main(){
printf("This is a test");
/* now exit */
}
Sample output:
#include<stdio.h>
int main(){
printf("This is a test");
}
2,shell脚本,其实是sed命令的一个例子
#!/bin/sed -f
# sed 清除c程序中的注释
#
# if no /* get next
/\/\*/!b
# here we've got an /*, append lines until get the corresponding
# */
:x
/\*\//!{
N
bx
}
# delete /*...*/
s/\/\*.*\*\///
(责任编辑:IT)
写了一段shell脚本,用来清除c代码中的注释,不敢独享,分享给大伙。
运行示例:Run this script as follows:
1,c代码示例
file.c:
#include<stdio.h>
2,shell脚本,其实是sed命令的一个例子
#!/bin/sed -f
# sed 清除c程序中的注释 # # if no /* get next /\/\*/!b # here we've got an /*, append lines until get the corresponding # */ :x /\*\//!{ N bx } # delete /*...*/ s/\/\*.*\*\/// |