文件批量入库脚本
Posted alisonman
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件批量入库脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
filedir=
tablename=
inm=`awk ‘$2=="‘${tablename}‘" {
if ($6=="1"){print $6
}else{
print $6}
}‘ 入库关系对应表.txt` #确认增量,全量
ses=`awk ‘$2=="‘${tablename}‘" {
if ($6=="1"){print $3
}else{
print $3}
}‘ 入库关系对应表.txt` #取分隔符
echo "spool $tablename.temp;
desc $tablename;
spool off; "|sqlplus -S 数据库登录用户和密码 >>/dev/null
if [ ${inm} -eq 1 ];then #当为增量时,采用追加入库
n=`cat $tablename.temp|wc -l`
cat $tablename.temp|sed -n "3,$n p"|awk ‘{print $1,$NF}‘|sed ‘$d‘|awk ‘BEGIN{
print "load data"
print "append"
print "into table ‘$tablename‘"
print "fields terminated by ‘\‘‘‘${ses}‘‘\‘‘"
print "(" } { if($2~/DATE/)
{print $1" date ‘\‘‘yyyy-mm-dd HH24:mi:ss‘\‘‘""," } eles
{print $1 " CHAR " "," } } ‘| sed ‘$s/,//‘|sed ‘$a )‘>${tablename}.ctl
else #当为全量时,采用覆盖入库
n=`cat $tablename.temp|wc -l`
cat $tablename.temp|sed -n "3,$n p"|awk ‘{print $1,$NF}‘|sed ‘$d‘|awk ‘BEGIN{
print "load data"
print "truncate"
print "into table ‘$tablename‘"
print "fields terminated by ‘\‘‘‘${ses}‘‘\‘‘"
print "(" } { if($2~/DATE/)
{print $1" date ‘\‘‘yyyy-mm-dd HH24:mi:ss‘\‘‘""," } eles
{print $1 " CHAR " "," } } ‘| sed ‘$s/,//‘|sed ‘$a )‘>${tablename}.ctl
fi
以上是关于文件批量入库脚本的主要内容,如果未能解决你的问题,请参考以下文章
redis 队列缓存 + mysql 批量入库 + php 离线整合