shell讀取文件update到數據庫(awk賦值給外部變量)
www.2cto.com
#!/bin/bash
FILE='20121224_Finaldatapm.csv'
MYSQL='/usr/local/mysql/bin/mysql'
USER='root'
PASSWD='root'
DB='ITIMS'
while read i
do
eval $(echo $i|awk -F',' '{ printf("a=%s\nb=%d\nc=%d\nd=%d\ne=%d\nf=%s",$1,$2,$3,$4,$5,$6); }')
SQL="update it_reportb set activeuser=$b,ctnpush=$c,wangmengnu=$d,wangmenguser=$e where name='$a' and date='$f'"
$MYSQL -u$USER -p$PASSWD $DB -e "$SQL"
done < $FILE