zoukankan      html  css  js  c++  java
  • [Linux] 大数据库导出大文件统计并去重

    1. 把数据库表导出到文本文件中

    mysql -h主机 -P端口 -u用户 -p密码 -A 数据库 -e "select email,domain,time from ent_login_01_000" > ent_login_01_000.txt

    总共要统计最近3个月的登陆用户 , 按月份分表,并且每月有128张表 , 全部导出到文件中 , 总共有80G

    2. grep 查出所有的2018-12 2019-01 2019-02

    find ./ -type f -name "ent_login_*" |xargs cat |grep "2018-12" > 2018-12.txt
    find ./ -type f -name "ent_login_*" |xargs cat |grep "2019-01" > 2019-01.txt
    find ./ -type f -name "ent_login_*" |xargs cat |grep "2019-02" > 2019-02.txt

    3.使用awk  sort 和 uniq 只取出前面的用户 , 并且先去一下重复行

    cat 2019-02.txt|awk -F " " '{print $1"@"$2}'|sort -T /mnt/public/phpdev/187_test/tmp/|uniq > 2019-02-awk-sort-uniq.txt

    cat 2019-01.txt|awk -F " " '{print $1"@"$2}'|sort -T /mnt/public/phpdev/187_test/tmp/|uniq > 2019-01-awk-sort-uniq.txt

    cat 2018-12.txt|awk -F " " '{print $1"@"$2}'|sort -T /mnt/public/phpdev/187_test/tmp/|uniq > 2018-12-awk-sort-uniq.txt

    uniq 只去除连续的重复行 , sort可以把行排成连续的 -T是因为默认占用/tmp的临时目录 , 根目录我的不够用了,因此改一下临时目录

    这几个文件占用了100多G

  • 相关阅读:
    变量与作用域
    安装node和grunt
    神奇的万维网
    大小写字母的转换
    跨域的方法
    选择器中含有空格的注意事项
    Tools
    jquery中innerWidth(),outerWidth(),outerWidth(true)和width()的区别
    网页中的foot底部定位问题
    CSS hack
  • 原文地址:https://www.cnblogs.com/taoshihan/p/10452782.html
Copyright © 2011-2022 走看看