忘记密码   免费注册 查看新帖 |

ChinaUnix.net

  平台 论坛 博客 文库 频道自动化运维 虚拟化 储存备份 C/C++ PHP MySQL 嵌入式 Linux系统
最近访问板块 发新帖
查看: 1465 | 回复: 5

多文件内容排序 [复制链接]

论坛徽章:
0
发表于 2018-03-05 09:47 |显示全部楼层
5可用积分
目录下有很多文件,比如:
todb-HTTP_BDR-180302-11596-1519979585.dat  todb-HTTP_BDR-180302-11596-1519980231.dat  todb-HTTP_BDR-180302-11596-1519980851.dat
todb-HTTP_BDR-180302-11596-1519979673.dat  todb-HTTP_BDR-180302-11596-1519980293.dat  todb-HTTP_BDR-180302-11596-1519980913.dat
todb-HTTP_BDR-180302-11596-1519979735.dat  todb-HTTP_BDR-180302-11596-1519980355.dat  todb-HTTP_BDR-180302-11596-1519980975.dat
todb-HTTP_BDR-180302-11596-1519979797.dat  todb-HTTP_BDR-180302-11596-1519980417.dat  todb-HTTP_BDR-180302-11596-1519981037.dat
todb-HTTP_BDR-180302-11596-1519979859.dat  todb-HTTP_BDR-180302-11596-1519980479.dat  todb-HTTP_BDR-180302-11596-1519981099.dat
todb-HTTP_BDR-180302-11596-1519979921.dat  todb-HTTP_BDR-180302-11596-1519980541.dat  todb-HTTP_BDR-180302-11596-1519981161.dat
todb-HTTP_BDR-180302-11596-1519979983.dat  todb-HTTP_BDR-180302-11596-1519980603.dat  todb-HTTP_BDR-180302-11596-1519981223.dat
todb-HTTP_BDR-180302-11596-1519980045.dat  todb-HTTP_BDR-180302-11596-1519980665.dat  todb-HTTP_BDR-180302-11596-1519981285.dat
todb-HTTP_BDR-180302-11596-1519980107.dat  todb-HTTP_BDR-180302-11596-1519980727.dat  todb-HTTP_BDR-180302-11596-1519981525.dat
todb-HTTP_BDR-180302-11596-1519980169.dat  todb-HTTP_BDR-180302-11596-1519980789.dat

每个文件内容格式如下:
1519979525,139930655,1519979525,472732920,45,360849820658635010,2,,,,1,3719393533,0,3719393333,0,0,0,2152,2152,0,147980,2518729005,0,65535,255,65535,4294967295,255,65535,65535,,103,-1.4294967295,-1.4294967295,40,217152000,0,0,0,0,1,177047186,18446744073709551615,18446744073709551615,37440,0,1,1960165575,18446744073709551615,18446744073709551615,8046,869,762,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,4294967295,0,0,0,61258,188695,272328,271555,0,332802,255,3,5,1,200,61431,61432,250119,116.213.192.199,16,/webgame/http.do,,Mozilla/5.0 (Linux; U; Android 2.3.4; zh-cn; GT-I9108 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML; like Gecko) Version/4.0 Mobile Safari/533.1,application/x-www-form-urlencoded,,sanguo.clientid=27856315545564606564; JSESSIONID=abc3hP_oXLqJm5,47,,0,3,0,0,0,,1,1,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1519979525,106854001,1519979525,786585235,45,367323745122510852,2,,,,1,3719393533,0,3719393392,0,0,0,2152,2152,0,57459,2881324036,0,65535,255,65535,4294967295,255,65535,65535,,103,-1.4294967295,-1.4294967295,1,217152000,0,0,0,0,1,177000717,18446744073709551615,18446744073709551615,45862,0,1,2013158430,18446744073709551615,18446744073709551615,80,459,361,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,4294967295,0,0,0,55119,524417,621349,0,0,679731,255,3,5,1,200,51856,51857,576264,api.jiepang.com,25,/friends/invitations.json,,,application/x-www-form-urlencoded,,,44,,0,3,0,0,0,,1,1,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1519979525,138834663,1519979525,345517347,45,362257195541999680,2,,,,1,3719393533,0,3719393387,0,0,0,2152,2152,0,142008,3701391377,0,65535,255,65535,4294967295,255,65535,65535,,103,-1.4294967295,-1.4294967295,1,79312000,0,0,0,0,1,179869989,18446744073709551615,18446744073709551615,41373,0,1,167772332,18446744073709551615,18446744073709551615,80,632,721,2,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,4294967295,0,0,0,2959,0,205165,203732,0,206682,255,3,6,1,200,96084,96085,205154,uppi.uccm.uc.cn,80,,,Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12,text/html; charset=UTF-8,,,212,,0,3,0,0,0,,1,1,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

要求:
[url=]取 52 53 54 55

按照52+53的和 倒序排名 取前100[/url]

最佳答案

查看完整内容

回复 5# dahe_1984 $ awk -F, '{a[$1]+=$2; b[$1]+=$3; c[$1]+=$4; d[$1]+=$5; e[$1]+=$6; f[$1]+=$7; }END{for(n in a){print n" "a[n]" "b[n]" "c[n]" "d[n]" "e[n]" "f[n]}}' FILE 1519979525 385619319 4559938575 1604835502 135 1090430761323145472 6 $ awk -F, '{a[$1];for(n=2;n

论坛徽章:
130
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07巳蛇
日期:2014-05-09 16:43:18巨蟹座
日期:2014-10-23 17:48:38子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59
发表于 2018-03-05 09:47 |显示全部楼层
本帖最后由 jason680 于 2018-03-07 07:00 编辑

回复 5# dahe_1984

$ awk -F, '{a[$1]+=$2; b[$1]+=$3; c[$1]+=$4; d[$1]+=$5; e[$1]+=$6; f[$1]+=$7; }END{for(n in a){print n" "a[n]" "b[n]" "c[n]" "d[n]" "e[n]" "f[n]}}' FILE
1519979525 385619319 4559938575 1604835502 135 1090430761323145472 6

$ awk -F, '{a[$1];for(n=2;n<=7;n+=1)s[$1,n]+=$n}END{for(t in a){p=t;for(n=2;n<=7;n+=1)p=p" "s[t,n];print p}}' FILE
1519979525 385619319 4559938575 1604835502 135 1090430761323145472 6

$ awk -F, 'BEGIN{c=split("2 3 4 5 6 7",d," ")}{a[$1];for(n=1;n<=c;n+=1)s[$1,d[n]]+=$d[n]}END{for(t in a){p=t;for(n=1;n<=c;n+=1)p=p" "s[t,d[n]];print p}}' FILE
1519979525 385619319 4559938575 1604835502 135 1090430761323145472 6

$ awk -F, 'BEGIN{c=split("2 3 5 7",d," ")}{a[$1];for(n=1;n<=c;n+=1)s[$1,d[n]]+=$d[n]}END{for(t in a){p=t;for(n=1;n<=c;n+=1)p=p" "s[t,d[n]];print p}}' FILE
1519979525 385619319 4559938575 135 6

论坛徽章:
0
发表于 2018-03-05 10:27 |显示全部楼层
cat *.dat | awk -F"," '{print ($52+$53), ($54 + $55),$52, $53, $54, $55}' |sort -k 1 -r -n  >/tmp/txt

一行搞定,自己回答了

论坛徽章:
0
发表于 2018-03-05 10:27 |显示全部楼层
cat *.dat | awk -F"," '{print ($52+$53), ($54 + $55),$52, $53, $54, $55}' |sort -k 1 -r -n  >/tmp/txt

自问自答了,一行搞定

论坛徽章:
0
发表于 2018-03-05 11:48 |显示全部楼层
还需要多第一列相同的其他列相加。
awk '{a[$1]+=$2; a[1]+=$3;}END{for(i in a){print i" "a[i]" "a[1];}}' /tmp/txt

这个只能加一列,多列相加怎么写?

论坛徽章:
0
发表于 2018-03-05 11:54 |显示全部楼层
awk '{a[$1]+=$2; b[$1]+=$3; c[$1]+=$4; d[$1]+=$5; e[$1]+=$6; f[$1]+=$7; }END{for(i in a){print i" "a[i]" "b[i]" "c[i]" "d[i]" "e[i]" "f[i];}}' /tmp/txt
您需要登录后才可以回帖 登录 | 注册

本版积分规则

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号 北京市公安局海淀分局网监中心备案编号:11010802020122
广播电视节目制作经营许可证(京) 字第1234号 中国互联网协会会员  联系我们:wangnan@it168.com
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP