- 论坛徽章:
- 0
|
linux -bash
配置文件是tabcol.lst
#schema tab colunm type value
cps tm_cust name varchar name2
cps tm_cust corp_nm int 25
spp t_bal colname varchar hello
go.sh
-----------------------------------------------------------------------------
#取得要更新的表
cat ini/db2col.lst | sed -e 's/#.*$//g' | awk 'BEGIN{OFS="\t"}{if(NF==5){print $1,$2}}' |sort |uniq |
while read schtab #schemaname tablename
do
schtab=($schtab)
schemaname=${schtab[0]}
tablename=${schtab[1]}
# echo $schemaname.$tablename
sqlstr="update $schemaname.$tablename set"
#echo 0 $sqlstr
colnum=0
#取得要更新的字段信息
cat ini/db2col.lst | sed -e 's/#.*$//g' | awk -v sch=$schemaname -v tab=$tablename '{if(sch == $1 && tab== $2){print $3,$4,$5}}' |
while read lineinfo #col typ val
do
lineinfo=($lineinfo)
col=${lineinfo[0]}
typ=${lineinfo[1]}
val=${lineinfo[2]}
colnum=`expr $colnum + 1`
if [ $colnum -ne 1 ]
then
sqlstr="$sqlstr,"
#echo 1 $sqlstr
fi
# echo $col -- $typ -- $val
if [ "$typ" == "varchar" -o "$typ" == "char" ]
then
sqlstr="$sqlstr $col='$val'"
#echo 2 $sqlstr
else
sqlstr="$sqlstr $col=$val"
#echo 3 $sqlstr
fi
echo 4 $sqlstr
done
echo 5 $sqlstr
#执行sql语句
done
在输出到echo 5 $sqlstr的地方执行sql,但这个地方的字符串没有显示全部。
困扰几天了。请高手们帮看一下。问题出在什么地方。循环内和循环外字符串的值居然不一样
|
|