教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 清除c语言代码中注释的shell脚本(sed)

清除c语言代码中注释的shell脚本(sed)

发布时间:2014-11-25   编辑:jiaochengji.com
本文介绍下,一段可以清除c语言代码中注释的shell脚本,有需要的朋友参考下。

写了一段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/\/\*.*\*\///

您可能感兴趣的文章:
清除c语言代码中注释的shell脚本(sed)
sed清除注释的脚本一例
linux shell中#!bin/sh的理解
sed单行命令大全 值得收藏
sed 去除shell中的注释
shell 去掉每行结尾的空格,附sed知识
python shell是什么
去除空格与数字的脚本
shell去除空格/删除空格/清除空格/去掉空格的方法
去除文件内容中的注释与空行的命令

[关闭]
~ ~