免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: KoomIer
打印 上一主题 下一主题

二维数组文件处理 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2014-11-28 08:37 |只看该作者
问题会不会出在这里

nohup awk '{p=$3;c[p]+=$5;d[p]+=$6}END{for(i in c)print i,c,d}' *.log > sta.data &


我们用了手机号$3做下标,导致每次找c的时候寻址空间太大


手机号的长度为11位
而我的手机数量其实只有百万级 也就是7位,
从而产生了寻址问题


另外还有就是这个加法,到底能算多大数据
单用户的数据量应该在一天的流量1G以内吧,用来做加法会有问题吗 ?
100000000


问题会不是出在这里啊


回复 6# reyleon


   

论坛徽章:
8
戌狗
日期:2014-09-26 16:39:44水瓶座
日期:2014-10-10 02:06:57金牛座
日期:2014-10-11 23:04:042015亚冠之首尔
日期:2015-06-23 15:37:0015-16赛季CBA联赛之天津
日期:2016-01-22 18:58:2915-16赛季CBA联赛之佛山
日期:2016-05-31 19:18:0815-16赛季CBA联赛之同曦
日期:2016-08-10 16:26:3315-16赛季CBA联赛之辽宁
日期:2018-01-10 11:47:40
12 [报告]
发表于 2014-11-28 14:18 |只看该作者
本帖最后由 wiliiwin 于 2014-11-30 16:35 编辑

此脚本输入你想要计算的列统计,列从0开始算起,比如服务代码这这列为1,就输入1,就可以算出来服务代码的统计信息,其他列依次类推。
  1. # more 29.txt
  2. Server03        1        936914594        198618649901541f        460019906205067f        1411040000442
  3. b0800        4158        6076        6        ;
  4. Server03        3        936914596        198618649901541f        460019906205067f        1411040000442
  5. b0800        4158        6076        5        ;
  6. Server03        1        936914594        198618649901541f        460019906205067f        1411040000442
  7. b0800        4158        6076        6        ;
  8. Server03        3        936914596        198618649901541f        460019906205067f        1411040000442
  9. b0800        4158        6076        5        ;
复制代码
  1. # more test.py
  2. #!/usr/bin/env python   
  3. hash={}
  4. num=int(raw_input('Enter a num:'))
  5. for line in open("29.txt"):
  6.     i=line.split()
  7.     if num==3:
  8.         i[num]=i[num][4:15]
  9.     elif num==5:
  10.         i[num]=i[num][0:12]  
  11.     if not hash.get(i[num]):
  12.        hash[i[num]]=[0,0]
  13.        hash[i[num]][0]+=int(i[6])
  14.        hash[i[num]][1]+=int(i[7])
  15.     else:
  16.        hash[i[num]][0]+=int(i[6])
  17.        hash[i[num]][1]+=int(i[7])
  18. for key in hash.keys():
  19.     print "%s\tup:%s\tdown:%s" %(key,hash[key][0],hash[key][1])  
复制代码

  1. 统计服务代码up和down总量
  2. #./test.py
  3. Enter a num:1
  4. 1        up:8316        down:12152
  5. 3        up:8316        down:12152
复制代码
  1. 统计手机号 up和down的总量
  2. # ./test.py
  3. Enter a num:3     
  4. 18649901541        up:20790        down:30380
复制代码

论坛徽章:
0
13 [报告]
发表于 2014-11-29 00:22 |只看该作者
#/usr/bin/python

upstream = 0
downstream = 0
serverup_dic = {}
serverdown_dic = {}

file_object = open('/root/ipall.txt','r')

for x in file_object:
    list = x.split()
    list[3] = list[3][4:15]
    list[4] = list[4][:-1]
    list[5] = list[5][0:12]
    if list[1] == "1":
        upstream = upstream + int(list[6])
        downstream = downstream + int(list[7])
    if serverup_dic.has_key(list[0]):
        serverup_dic[list[0]] = serverup_dic[list[0]] + int(list[6])
    else:
        serverup_dic[list[0]] = int(list[6])

    if serverdown_dic.has_key(list[0]):
        serverdown_dic[list[0]] = serverup_dic[list[0]] + int(list[7])
    else:
        serverdown_dic[list[0]] = int(list[7])

    print list

print "the server 1 upload traffic is %uk" % upstream
print "the server 1 load traffic is %uk" % downstream
for key,value in serverup_dic.items():
    print "phone %s upload traffic is %uk" % (key,value)
for key,value in serverdown_dic.items():
    print "phone %s download traffic is %uk" % (key,value)

file_object.close()
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP