Chinaunix首页 | 论坛 | 博客
  • 博客访问: 411304
  • 博文数量: 403
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -70
  • 用 户 组: 普通用户
  • 注册时间: 2016-09-05 12:45
文章分类

全部博文(403)

文章存档

2014年(3)

2013年(1)

2012年(3)

2011年(21)

2010年(13)

2009年(64)

2008年(9)

2007年(36)

2006年(253)

分类: LINUX

2009-10-21 13:54:00

#!/bin/bash
###the script use to delete comment
if [ -z "$1" ];then               
     echo "ipput the source file"
     exit 1
fi
postfix=`echo $1 |cut -f 2 -d '.'` 
if [ -n "$2" ];then                 
     target_file=$2                 
     touch ${target_file}
else
prefix=`echo $1|cut -f 1 -d '.' `
     target_file=${prefix}.temp
     touch ${target_file}
fi
case $postfix in
          sh )
              echo "it is shell script !"
              sed 's/[[:space:]]#.*//g' $1 |sed '/^#/d'|\
              sed '/^[[:space:]]*$/d' | sed '/^$/d' >${target_file}
              echo "the source file is $1,target file is ${target_file}"
              ;;
       c|java)
              echo "c  or java program"
              sed 's/\/\*.*\*\///g' $1|sed '/\/\*/,/.*\*\//d' |\
              sed 's/\/\/.*//g' |\
              sed '/^[[:space:]]*$/d' |sed '/^$/d' >${target_file}
              echo "the source file is $1,target file is ${target_file}"
              ;;
 conf)
  echo "it is config file!"
              sed 's/[[:space:]]#.*//g' $1 |sed '/^#/d'|\
              sed '/^[[:space:]]*$/d' | sed '/^$/d' >${target_file}
              echo "the source file is $1,target file is ${target_file}"
              ;;
        *)
              echo "unknown file type !"
              rm -f ${target_file}
              ;;
esac
注意:
1.copy的时候copy到txt中,然后以二进制形式传到linux机器上。
2.没有二进制传输工具的情况下,将copy到linux中的文件执行如下命令:
sed -i "s/\r//" del_comment 其中,del_comment是你传上去的文件名字
3.chmod u+x del_comment使其可以执行
4.使用方法:
del_comment 源文件(可以包括路径)  目标文件(可选,可以包含路径)
5.没有写目标文件的话,执行后将会在源文件所在目录创建一个与源文件同名的.temp文件。
6.脚本可以加其它内容,可以修改文件名后缀,本脚本只是实现了对JAVA、C、conf、sh文件的注释的删除,需要的话可以再加。
阅读(928) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~