开始记录一些东西
一个生成CTL文件的SHELL
上一篇 /
下一篇 2008-06-25 14:14:40
#! /usr/bin/sh
cat filelist | while read line
do
TableName=$line
echo $TableName
sqlstr="desc $TableName;"
# a sql statement
echo "set linesize 50">tmp.sql
echo "spool "$TableName"_column.txt">>tmp.sql
echo $sqlstr >>tmp.sql
echo "quit;">>tmp.sql
# execute the sql
sqlplusUSER/PASSWORD@NETNAME @tmp.sql >/dev/null
awk '{if(NR!=1 && NR!=2) print $1}' $TableName'_column.txt' >1.txt
sed '/^$/d' 1.txt > $TableName'_column.txt'
ColName=''
cat $TableName'_column.txt' | while read LINE
do
ColName=$ColName$LINE','
done
echo "LOAD DATA\nINTO TABLE $TableName\nappend\nfields terminated by \"|#|#|\"\n(" > $TableName.ctl
echo $ColName | sed 's/,$//' | awk -F, '{for(i=1;i<NF;i++) printf "%s,\n",$i } {print $NF}' >> $TableName.ctl
echo ")" >> $TableName.ctl
done
-----------------------------------------
补充说明:filelist是一个文件,里面存放的是要生成ctl文件的表名,格式如下:
come_account
go_account
相关阅读:
- SED 手册 (ainux, 2008-5-12)
- sed基础概念 (ainux, 2008-5-12)
- 在第n行插入内容(sed) (ainux, 2008-5-12)
- 关于变量赋值 (ainux, 2008-5-12)
- Linux SHELL if 命令参数说明 (ainux, 2008-5-12)
- 对文本的行列操作 (ainux, 2008-5-16)
- ()和{ }还是不一样的 (ainux, 2008-5-18)
- sed附加文本 (ainux, 2008-5-19)
- shell的内置命令 (thefirstred, 2008-5-20)
- linux性能检测结果发到指定的邮箱脚本 (ainux, 2008-6-20)
收藏
举报
TAG:
ctl文件
导入导出数据
shell