ikegami

Untitled

Jul 22nd, 2021 (edited)
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. # `natsort` from Sort::Key::Natural would be better than `sort`.
  2. # To use this:
  3. # * Install the module,
  4. # * Pass the `-MSort::Key::Natural=natsort` switch to `perl`, and
  5. # * Replace the three instances of `sort` with `natsort`.
  6.  
  7. perl -lane'
  8.   $data{$F[1]}{$F[2]}{$F[3]} = $F[0];
  9.   ++$cols{$F[3]};
  10.   END {
  11.      local $, = "\t";
  12.      my @cols = sort keys(%cols);
  13.      print undef, undef, @cols;
  14.      for my $x (sort keys(%data)) {
  15.         for my $y (sort keys(%{$data{$x}})) {
  16.            print $x, $y, map { $data{$x}{$y}{$_} } @cols;
  17.         }
  18.      }
  19.   }
  20. '
  21.  
  22. # Output:
  23. #                 z1      z2
  24. # x1      x1      20
  25. # x1      y1      10      19
  26. # x2      y1      16      12
  27. # x2      y2      15
  28. # y1      y1              11
  29.  
Add Comment
Please, Sign In to add comment