#!/bin/sh
cd /u01/app/oracle/oradata/ext
ls -l *.csv|awk '{print $9}'| while read line
# 输出扩展名为.csv的所有文件名追加到文件countstat.txt
echo ${line} >> /root/countstat.txt
# 输出扩展名为.csv的每个文件记录行数追加到文件countstat.txt
cat ${line} | wc -l >> /root/countstat.txt
TABLE=`echo ${line}|awk -F "." '{print $1}'`
# 输出oracle表名称追加到文件countstat.txt
echo $TABLE >> /root/countstat.txt
# 查询oracle数据库中表记录总数追加到文件countstat.txt
su - oracle -c "sqlplus /nolog <<EOF
select count(*) from $TABLE;
sed '/^SQL/d' /root/countstatbak.txt |sed '/^$/d'|sed '/^Copyright/d'|sed '/^With/d'|sed '/^-/d'|sed '-e /COUNT/d'|sed 's/^[[:space:]]*//g'> /root/result.txt
-e /COUNT/d 删除包含COUNT字符的所有行,无论匹配字符在行首、行中或者行尾什么地方
s/^[[:space:]]*//g 删除行首空格
本文转自 pgmia 51CTO博客,原文链接:http://blog.51cto.com/heyiyi/1170001