码迷,mamicode.com
首页 > 其他好文 > 详细

工作脚本处理文本

时间:2015-06-02 18:03:22      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:

简单的使用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



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

工作脚本处理文本

标签:

原文地址:http://blog.csdn.net/wallwind/article/details/46331227

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!