Chinaunix首页 | 论坛 | 博客
  • 博客访问: 260153
  • 博文数量: 54
  • 博客积分: 35
  • 博客等级: 民兵
  • 技术积分: 729
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-09 10:35
文章分类

全部博文(54)

文章存档

2014年(37)

2013年(17)

分类: LINUX

2013-12-25 15:29:19

原帖:处理前:
professor.hut gilligan.crew.hut 1250
professor.hut lovey.howell.hut 910
thurston.howell.hut lovey.howell.hut 1250
professor.hut lovey.howell.hut 450
professor.hut laser3.copyroom.hut 2924
ginger.girl.hut professor.hut 1218
ginger.girl.hut maryann.girl.hut 199

处理后:
professor.hut has sent 5534 bytes
  professor.hut => laser3.copyroom.hut: 2924 bytes
  professor.hut => lovey.howell.hut: 1360 bytes
  professor.hut => gilligan.crew.hut: 1250 bytes
ginger.girl.hut has sent 1417 bytes
  ginger.girl.hut => professor.hut: 1218 bytes
  ginger.girl.hut => maryann.girl.hut: 199 bytes
thurston.howell.hut has sent 1250 bytes
  thurston.howell.hut => lovey.howell.hut: 1250 bytes

处理规则:
统计第一字段相同的值(第三字段)的总和并统计第一字段和第二字段相同的值的和,并按由大到小的顺序排列。

点击(此处)折叠或打开

  1. #!/usr/bin/perl
  2. use 5.010;
  3. my ( %total, %sum );
  4. while (<DATA>) {
  5.         @_ = split;
  6.         $total{$_[0]} += $_[2];
  7.         $sum{$_[0]}{$_[1]} += $_[2];
  8. }
  9. for my $key ( sort { $total{$b} <=> $total{$a} } keys %total ) {
  10.         say "$key has sent $total{$key} bytes";
  11.         for ( sort { $sum{$key}{$b} <=> $sum{$key}{$a} } keys %{$sum{$key}} ) {
  12.                 say " $key => $_: $sum{$key}{$_} bytes";
  13.         }
  14. }
  15. __DATA__
  16. professor.hut gilligan.crew.hut 1250
  17. professor.hut lovey.howell.hut 910
  18. thurston.howell.hut lovey.howell.hut 1250
  19. professor.hut lovey.howell.hut 450
  20. professor.hut laser3.copyroom.hut 2924
  21. ginger.girl.hut professor.hut 1218
  22. ginger.girl.hut maryann.girl.hut 199


阅读(1199) | 评论(0) | 转发(0) |
0

上一篇:无序输出文本

下一篇:sed打点计数法

给主人留下些什么吧!~~