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
我的AWK脚本
最新推荐文章于 2024-05-17 17:04:37 发布