Created
January 17, 2014 16:40
-
-
Save kindy/8476631 to your computer and use it in GitHub Desktop.
used to count stream size. like tee, but not save stream to file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# head -c123456845 /dev/random | szstat >/dev/null | |
sub ps { | |
my $n=shift @_; | |
my @u=qw"B K M G T P E"; | |
my $i=0; | |
while ($n>=1024 and $i<$#u) { | |
$n /= 1024.0; | |
$i += 1; | |
} | |
return sprintf("% 10.3f $u[$i]", $n); | |
} | |
$n = 2 * 1024; # copy per 2k | |
while ($n2 = read STDIN,$in,$n) { | |
print $in; # output everything | |
$c += $n2; | |
print STDERR ("\r" . ps($c)) if ($c%(1024)==0); | |
} | |
print STDERR "\ntotal: ", ps($c), "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment