我的AWK脚本

echo "export album"
mysql -uroot -h$DBIP Resource -e "select id, artistid from Album;" | sed -e "1d" > ${DBFILE}/album.txt

echo "export music"
mysql -uroot --default-character-set=gbk -DResource -e 'select id,artistid,mkvrid from Music;' |sed -e '1d' >$DATA/musicid_artistid.txt

#music number & mv number
awk 'BEGIN { FS="\t";OFS="\t";while(getline < "data/musicid_artistid.txt") {artist_map[$2]=0;mv_map[$2]=0;} } {artist_map[$2] += 1; if(($3 + 0) > 0){mv_map[$2] += 1;}} END {for( i in artist_map ) print i, artist_map[i], mv_map[i]}' data/musicid_artistid.txt > tempartist1

awk 'BEGIN {FS="\t";OFS="\t";while(getline<"data/album.txt"){artist_map[$2]=0;}} {artist_map[$2] += 1} END{for( i in artist_map) print i, artist_map[i]}' data/album.txt > tempartist2

sqlFile="data/updateArtist.sql"
awk 'BEGIN {FS="\t";OFS="\t";while(getline<"tempartist2"){artist_map[ $1 ]=$2;}} { albumnum=artist_map[ $1 ]; if(albumnum == "" ) albumnum = 0;print "update Artist set songnum = "$2 ", mvnum = "$3 ",albumnum = "albumnum " where id = " $1 ";"} ' tempartist1 > ${sqlFile}

rm tempartist1 tempartist2

if [ -f ${sqlFile} ]; then
    LINE=`cat ${sqlFile} | wc -l`
        if [ $LINE -gt 5000 ] ; then       #脚本文件存在而且sql数目大于5000才执行
        mysql -uroot -DResource < ${sqlFile}
        echo "OK"
                exit 0
        fi
fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值