#登录pgsql客户端
#数据文件位置
PATH_FILE="/home/dzh"
if [ "$#" -eq 1 ]; then
load_file=$1
else
load_file=`空值`
fi
echo ${load_file}
#load_holo_file=$(echo $load_file | sed 's/.sql//')
########## 文件名称格式如下 ###########
#sellermanage.t_businessmanage_rule_enterprise.sql
#sellermanage.t_sps_channel.sql
#sellermanage.t_sps_supplier_mp.sql
#获取文件下的所有文件
dir=$(ls -l ${PATH_FILE}/data_file/ |awk '/^-/ {print $NF}')
for ifile in $dir
do
#获取文件名称
echo $ifile
#获取库名称表明
db_table_name=$(echo ${ifile}|cut -d '.' -f 1,2)
table_name=$(echo ${ifile}|cut -d '.' -f 2)
new_table_name=ods.$(echo ${db_table_name} | sed 's/\./_/g')
echo ${table_name}
echo ${new_table_name}
#判断文件编码
filecode="file ${PATH_FILE}/data_file/${ifile}"
#echo ${filecode}
yn_utf8=$(echo ${filecode}|awk '{run=$0;system(run)}'|cut -d ' ' -f 2)
echo "$file编码(utf8或者其他)--${yn_utf8}"
if [ ${yn_utf8} == 'UTF-8' ] ; then
#文件内容统替换
#sed -e"s/\"/'/g" -e"s/\\\'/\\\\\"/g" -e's/`//g' -e"s/;/on conflict do nothing;/" -i
${PATH_FILE}/data_file/${ifile}
#
sed -e"s/\"/'/g" -e"s/\\\'/\\\\\"/g" -e's/`//g' -e"s/);/)on conflict do nothing;/" -e"s/\
<${table_name}\>/${new_table_name}/g" -i ${PATH_FILE}/data_file/${ifile}
#加载数据到holo
export PGPASSWORD=*
psql -h * -p80 -U* -d test02 -f ${PATH_FILE}/data_file/${ifile} >>/home/dzh/test.txt
echo "load ${table_name}"
else
echo "其他编码"
fi
done
# 读取数据文件循环体
###cat ${PATH_FILE}/${load_file}| while read line
# 循环处理
###do
#echo $line
#处理变量值的双引号转单引号
###line2=$(echo $line | sed 's/''"'/"'"'/g')
#echo $line2
#最后一行是分号时增加 主键重复跳过
###final=`echo ${line2: -1}`
###if [ ${final} == ';' ]; then
### line2=$(echo $line2 | sed 's/;/on conflict do nothing;/')
###fi
###echo ${line2}>>${PATH_FILE}/${load_holo_file}_holofile.sql
###done
#循环体结束
#文件最后一行增加特殊处理
#cat /home/dzh/test_load_file.sql|tail -1 | sed 's/;/on conflict do nothing;/'
#加载到HOLO 语句
#export PGPASSWORD=*
#psql -h * -p80 -U* -d test02 -f ${EXE_FILE}/${load_file} >/home/dzh/test.txt