From a6ca40bac5748226cf0816193f6cb89ca5a02bb7 Mon Sep 17 00:00:00 2001 From: zhaigy Date: Thu, 27 Sep 2012 18:41:27 +0800 Subject: [PATCH] fix --- cdh4/author.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 cdh4/author.sh diff --git a/cdh4/author.sh b/cdh4/author.sh new file mode 100644 index 0000000..017073e --- /dev/null +++ b/cdh4/author.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# coding=utf-8 +# Author: zhaigy@ucweb.com +# Data: 2012-09 + +heads="" +JH='#' + +while read LINE; do + char=${LINE:0:1} + if [ "$char" != $JH ] + then + break; + fi + if [ -z "$heads" ]; then + heads="${LINE}"; + else + heads="${heads}\n${LINE}"; + fi +done < $0 + +bn=`basename $0` +#echo $heads + +function delete_head_annotation +{ + j=0 + while read LINE; do + char=${LINE:0:1} + #if [ "$char" != $JH -a "$char" != "{" ] + if [ "$char" != $JH ] + then + break; + fi + j=$[j+1] + done < $1 + sed -i "1,${j}d" $1 +} + +DIR=${1:-"."} +DIR=${DIR%/} + +for f in `ls $DIR/*.sh|grep -v $bn`; do + echo $f + delete_head_annotation $f + sed -i -e "1i\\${heads}" $f +done