postgrsql-数据文件加载PG数据库或者HOLO- shell 脚本

#登录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

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值