• awk处理文件内容格式


    今天运营出了点问题,需要对特定时间段充值数做一个处理,文件格式有特定要求,要符合erlang的格式
    {roleID,gold}.
    mysql导出所有数据
    结果如下【取部分数据看】:
    ===================================
    kuwo    4       50004106230500  100
    kuwo    4       50004106230900  10
    agent   server  role_id ****
    uu178   5       380005100002500 300
    agent   server  role_id ****
    uu178   6       380006100000600 200
    uu178   6       380006100110500 20
    agent   server  role_id ****
    yy365   1       860001100008000 2000
    yy365   1       860001100008100 1900

    ===================================
    首先去掉表头信息:
    cat log.txt | grep -v agent
    kuwo    4       50004104005100  50
    kuwo    4       50004104284100  1000
    kuwo    4       50004105824300  1000
    kuwo    4       50004106230500  100
    kuwo    4       50004106230900  10
    uu178   5       380005100002500 300
    uu178   6       380006100000600 200
    uu178   6       380006100110500 20
    yy365   1       860001100008000 2000
    yy365   1       860001100008100 1900
    ==============================
    去掉第一列每二列
    cat log.txt | grep -v agent | awk '{print $3,$4}'
    50004104005100 50
    50004104284100 1000
    50004105824300 1000
    50004106230500 100
    50004106230900 10
    380005100002500 300
    380006100000600 200
    380006100110500 20
    860001100008000 2000
    860001100008100 1900
    拼凑格式
    cat log.txt | grep -v agent | awk '{print $3,$4}'|  awk '{print "{"$1",",$2"}."}'
    {50004104005100, 50}.
    {50004104284100, 1000}.
    {50004105824300, 1000}.
    {50004106230500, 100}.
    {50004106230900, 10}.
    {380005100002500, 300}.
    {380006100000600, 200}.
    {380006100110500, 20}.
    {860001100008000, 2000}.
    {860001100008100, 1900}.
    ====================================
    大功告成,比用脚本去逐行生成文件快多了
    最后,整个过程可整理成一条管道命令
    cat log.txt | grep -v agent | awk '{print "{"$3",",$4"}."}' > newfile.txt
     




  • 相关阅读:
    网络设备安全需求规格
    web安全法则
    Write Hole 问题
    如何同步master的代码到fork分支代码
    Self assignment
    Uninitialized scalar variable
    Operands of different size in bitwise operation
    Insecure Compiler Optimization
    negative array index read
    Unintended sign extension
  • 原文地址:https://www.cnblogs.com/firmy/p/2707647.html
Copyright © 2020-2023  润新知