使用文字處理命令抽取/ORACLE/RDBMS/admin目錄下指令碼的註釋資訊(可以使用正規表示式匹配)

oxoxooxx發表於2011-01-23

#!/bin/sh

#使用文字處理命令抽取/ORACLE/RDBMS/admin目錄下指令碼的註釋資訊
set echo on
echo "clean env..."
mkdir temp
rm -f result.txt


#獲取/ORACLE/RDBMS/admin目錄下的檔案列表:
echo "get sql file list ..."
ls -l $ORACLE_HOME/rdbms/admin |awk '{print $NF}'|grep .sql$ >sql.list

#替換所有檔案中所有^M字元:
echo "replace ^M char ..."
while read line
do
sed 's/^M//g' $ORACLE_HOME/rdbms/admin/$line >./temp/$line
done
#輸出需要列印的檔案及始末行行號到info.txt檔案中:
echo "output file ,start and end line number to print ..."
for i in `cat sql.list`
do
awk -v var=$i 'BEGIN{i=1&&j=1}
$0=="rem NAME"
||$0=="-- NAME"
||$0=="Rem NAME"
||$0=="Rem NAME"
||$0=="Rem NAME"
||$0=="REM NAME"
||$0=="rem NAME"
||$0=="rem NAME"
||$0=="REM NAME"
{i=NR}
$0=="rem MODIFIED"
||$0=="-- MODIFIED MM/DD/YY"
||$0=="Rem MODIFIED (MM/DD/YY)"
||$0=="Rem MODIFIED (MM/DD/YY)"
||$0=="Rem MODIFIED"
||$0=="REM MODIFIED (MM/DD/YY)"
||$0=="rem MODIFIED (MM/DD/YY)"
||$0=="rem MODIFIED (MM/DD/YY)"
||$0=="REM MODIFIED (MM/DD/YY)"
||$0=="Rem MODIFIED"
||$0=="Rem MODIFIED (MM/DD/YY)"
{j=NR}END{print var,i,j - 1}' ./temp/$i>>info.txt;
done

##cat info.txt |grep "1 1" |wc -l

#輸出所有檔案的註釋資訊到result.txt檔案中:
echo "print descripiton info to result.txt..."

while read line
do
a=`echo $line|cut -d" " -f1`
echo $a
b=`echo $line|cut -d" " -f2`
echo $b
c=`echo $line|cut -d" " -f3`
echo $c
sed -n "${b},${c}p" $a>>result.txt
echo "------------------------">>result.txt
done

echo "clean temp file ..."
rm -f ./info.txt
rm -rf ./temp
rm -f sql.list

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23937368/viewspace-1045063/,如需轉載,請註明出處,否則將追究法律責任。

相關文章