[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
做做样子,
  1. use utf8;
  2. use Encode;
  3. use Modern::Perl;
  4. use File::Slurp;
  5. use Date::Format;
  6. use List::Util qw/sum/;
  7. STDOUT->autoflush(1);
  8. my $jhref = load_hash( "./se/jhref.txt" );
  9. my $ipref = load_hash( "./se/ipref.txt" );
  10. my @items = load_item( "./se/wltj201906.txt" );
  11. for my $f ( sort { (stat($a))[9] <=> (stat($b))[9] } glob "*.txt" )
  12. {
  13.     next unless $f =~ /(\w+)\s+(\d+)/;
  14.     my $id = $1;
  15.     my $text = read_file($f);
  16.     my @count = map { $text =~ s/${_}//g } @items;
  17.     printf "%-25s %-9s %-10s %-10s %d %d %d %d %d %d %d\n",
  18.         encode('gbk', time2str( "%Y年%m月%d日%k:%M:%S", (stat($f))[9])),
  19.         $id,
  20.         exists $ipref->{$id} ? $ipref->{$id} : "-",
  21.         exists $jhref->{$id} ? $jhref->{$id} : "-",
  22.         @count,
  23.         sum(@count);
  24. }
  25. sub load_item
  26. {
  27.     my ($head) = read_file( $_[0] );
  28.     my @items = split(/\s+/, $head);
  29.     return grep { s/[\/\*].*// } @items[4..9];
  30. }
  31. sub load_hash
  32. {
  33.     my @lines = read_file( $_[0] );
  34.     my $hash = {};
  35.     for my $e ( grep { /^(j|p)/i } @lines )
  36.     {
  37.         my ($head, @list) = split(/\s+/, $e);
  38.         grep { s/\*//; $hash->{$_} = $head } @list;
  39.     }
  40.     return $hash;
  41. }
复制代码
补充结果:
  1. 2019年06月10日 9:37:44    B096      ping220    jh89       0 5 0 0 0 0 5
  2. 2019年06月10日 9:37:47    B105      ping220    jh90       0 2 0 0 0 0 2
  3. 2019年06月10日 9:37:48    B093      ping220    -          0 7 0 0 0 0 7
  4. 2019年06月10日 9:41:17    B079      ping230    jh89       0 2 0 0 0 0 2
  5. 2019年06月10日 9:41:19    B078      ping221    jh89       0 3 0 0 0 0 3
  6. 2019年06月18日10:54:36    B105      ping220    jh90       0 3 0 0 0 0 3
  7. 2019年06月18日10:54:36    B111      ping230    jh90       0 3 0 0 0 0 3
  8. 2019年06月18日10:54:39    B090      ping1      jh90       0 3 0 0 0 0 3
  9. 2019年06月18日10:54:39    B110      -          jh90       0 2 0 0 0 0 2
  10. 2019年06月19日20:19:59    B254      -          jh0        0 3 0 1 5 0 9
  11. 2019年06月20日19:00:05    B074      ping221    jh89       1 2 0 0 0 0 3
  12. 2019年06月20日19:03:16    B074      ping221    jh89       1 1 0 0 0 0 2
复制代码
错了也不改,逃

TOP

返回列表