首页 > 代码库 > 工作脚本处理文本

工作脚本处理文本

简单的使用shell,并且平时学习一下,假设不动手写的话。真是全然没有啥用啊。

所以。代码还是写出来的。


把下边的脚本代码贴出来。怕忘记了。


涉及到数据库连接,awk使用,日期函数,字符串模糊匹配。


#!/bin/bash

DIR_DATE=`date +"%Y%m%d" -d "-1 days"`
mkdir -p ~/export/$DIR_DATE

myfunc()
{
        for x in $(ls)
        do
                if [ -f "$x" ];then
                       if [[ "$x" =~ music_cgamev2_d* ]] && [[ "$x" =~ .*\.log.1.gz ]];then
                                                        #echo "$x";
                                                        zgrep "LoginGame" $x |grep "info" |awk -F" " ‘{print $2 ":" $3 ":" $9 ":" $10 ":" $11}‘ |awk -F":" ‘{print $1"   "$2":"$3":"$4"  "$6"    "$8"     "$10"    "}‘ >> ~/export/$DIR_DATE/denglu_94_$DIR_DATE.txt
                                                fi
                                                #if [[ "$x" =~ .*\.log.1.gz ]];then
                                                #       echo "$x";
                                                #fi
                elif [ -L "$x" ];then
                        echo "this is a link";
                else
                        cd "$x";
                        myfunc;
                        cd ..
                fi
        done
}

myfunc



#! /bin/bash

DATE=`date +"%Y_%-m_%-d" -d "-1 days" `
DIR_DATE=`date +"%Y%m%d" -d "-1 days"`
mkdir -p /data/cgame/$DIR_DATE
CONN_MYSQL="mysql ~~~~~"


echo "select  * from cgame_history.log_pay_$DATE;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/log_pay_$DATE.txt
echo "select  * from cgame_history.log_money_$DATE;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/log_money_$DATE.txt
echo "select  * from cgame_history.log_items_$DATE;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/log_items_$DATE.txt
echo "select uid, name, jewel, gold, starLevel, chessCount, pay_jewel, pay_gold, FROM_UNIXTIME(traceTime-28800) from card_game.game_player order by traceTime asc;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/player_$DATE.txt

echo "select uid,stone_num,FROM_UNIXTIME( day, ‘%Y%m%d‘ ) as dates from card_game.game_anchor_rank  where FROM_UNIXTIME( day, ‘%Y%m%d‘ ) =$DIR_DATE ORDER BY stone_num desc ;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/anchor_rank_$DATE.txt

echo "select uid,stone_num,FROM_UNIXTIME(day, ‘%Y%m%d‘) as dates from card_game.game_player_rank where FROM_UNIXTIME(day,‘%Y%m%d‘)=$DIR_DATE ORDER BY stone_num desc LIMIT 0,10;"|$CONN_MYSQL > /data/cgame/$DIR_DATE/user_rank_$DATE.txt



写的不好,仅仅是实现了功能。有些东西都能够抽出来当做变量, 让代码更加可读。

工作脚本处理文本