当前位置: 技术问答>linux和unix
awk调用函数的问题,请高手帮忙解答
来源: 互联网 发布时间:2015-07-10
本文导语: while read LINE do echo ${LINE} | nawk -F, ' BEGIN { temp="" } { temp= "insert into ${tablename} values"+"("+checkType("'$arg1'",$1)+","+checkType("'$arg2'",$2)+","+checkType("'$arg3'",$3)+","+checkType("'$arg4'",$4)+","+checkType("'$arg5'",$5)+","+checkType("'...
while read LINE
do
echo ${LINE} | nawk -F, ' BEGIN { temp="" } {
temp= "insert into ${tablename} values"+"("+checkType("'$arg1'",$1)+","+checkType("'$arg2'",$2)+","+checkType("'$arg3'",$3)+","+checkType("'$arg4'",$4)+","+checkType("'$arg5'",$5)+","+checkType("'$arg6'",$6)+","+checkType("'$arg7'",$7)+")";
printf("------%sn",checkType("'$arg1'",$1));
printf("%sn",temp)>>"load_data.txt";
}
function checkType(type,data){
if(type=="0"){
return data;
}else if (type=="1"){
temp="'"+data+"'"; -------A
return temp;
}
}
'
done temp = "" + data + "";
awk输出后进行tr "" "'"
do
echo ${LINE} | nawk -F, ' BEGIN { temp="" } {
temp= "insert into ${tablename} values"+"("+checkType("'$arg1'",$1)+","+checkType("'$arg2'",$2)+","+checkType("'$arg3'",$3)+","+checkType("'$arg4'",$4)+","+checkType("'$arg5'",$5)+","+checkType("'$arg6'",$6)+","+checkType("'$arg7'",$7)+")";
printf("------%sn",checkType("'$arg1'",$1));
printf("%sn",temp)>>"load_data.txt";
}
function checkType(type,data){
if(type=="0"){
return data;
}else if (type=="1"){
temp="'"+data+"'"; -------A
return temp;
}
}
'
done temp = "" + data + "";
awk输出后进行tr "" "'"