$opt{trim} *= $opt{width} / 100 if $opt{trimpct};
$opt{units} = [split //, ' kMGTPEZYRQqryzafpn'.($opt{ascii} ? 'u' : 'μ').'m']
if $opt{'human-readable'};
-$opt{anchor} //= qr/\A/;
$opt{'value-length'} = 4 if $opt{units};
$opt{'value-length'} = 1 if $opt{unmodified};
$opt{'signal-stat'} //= exists $SIG{INFO} ? 'INFO' : 'QUIT';
eval {
require Tie::Array::Sorted;
tie @order, 'Tie::Array::Sorted', sub { $_[1] <=> $_[0] };
- } or warn $@, "Expect slowdown with large datasets!\n";
+ } or warn $@, "Expect slowdown with large datasets!\n"
+ unless $opt{count};
}
my $float = qr<[0-9]* [.]? [0-9]+ (?: e[+-]?[0-9]+ )?>; # positive numberish
-my $valmatch = qr< $opt{anchor} ( \h* -? $float |) >;
+my $valmatch = $opt{anchor} // qr/\A/;
+$valmatch .= !$opt{count} ? qr/( \h* -? $float |)/ :
+ $opt{anchor} ? qr/(\S*)/ : qr/(.*)/;
+
while (defined ($_ = $opt{input} ? shift @{ $opt{input} } : readline)) {
s/\r?\n\z//;
+ my $valnum;
if ($opt{count}) {
- my ($valnum) = m/$opt{anchor} (\S*)/;
- $valnum //= '';
+ $valnum = m/$valmatch/ && $1;
$uniq{$valnum}++ and next;
- push @lines, "\n " . $_;
push @values, $valnum;
- next;
+ s/\A/\n /;
+ }
+ else {
+ s/\A\h*// unless $opt{unmodified};
+ $valnum = s/$valmatch/\n/ && $1;
+ push @values, $valnum;
+ push @order, $valnum if length $valnum;
}
- s/\A\h*// unless $opt{unmodified};
- my $valnum = s/$valmatch/\n/ && $1;
- push @values, $valnum;
- push @order, $valnum if length $valnum;
+
if (defined $opt{trim} and defined $valnum) {
my $trimpos = abs $opt{trim};
$trimpos -= length $valnum if $opt{unmodified};
}
}
push @lines, $_;
+}
+continue {
show_lines() if defined $opt{interval} and $opt{interval} < 0
and $. % $opt{interval} == 0;
}
my $limit = $opt{hidemax} ? $opt{hidemax}->($#lines, $nr) : $#lines;
if ($opt{count}) {
- $_ = $uniq{$_} for @values;
+ $_ = $uniq{$_} for @values[$nr .. $limit];
@order = @values;
}
if ($opt{markers} and $size > 0) {
for my $markspec (split /\h/, $opt{markers}) {
my ($char, $func) = split //, $markspec, 2;
+ my $increment = $func =~ s/[+]\z//;
my @pos = eval {
if ($func eq 'avg') {
return sum(@order) / @order;
$pos -= $minval;
$pos &&= log $pos if $opt{log};
$pos >= 0 or next;
- color(36) for $barmark[$pos / $range * $size] = $char;
+ $increment ||= $minval && !$pos;
+ color(36) for $barmark[$pos / $range * $size + $increment + .5] = $char;
}
}
$nr++;
}
say $opt{palette} ? color(0) : '' if $opt{spark};
+%uniq = () if $opt{interval} and $opt{count};
return $nr;
}
Contents are concatenated similar to I<cat>,
but numbers are reformatted and a bar graph is appended to each line.
-Don't worry, barcat does not drink and divide.
It can has various options for input and output (re)formatting,
but remains limited to one-dimensional charts.
For more complex graphing needs
=item B<-c>, B<--count>
Omit repetitions and count the number of occurrences.
-Similar to piping input to C<sort | uniq -c>
+Similar to piping input through C<sort | uniq -c>
but keeping the order of first appearances.
+Lines are omitted if they (or a specified field) are identical,
+and the amount of matches is prepended and used as values
+for bars and subsequent statistics.
+
=item B<-f>, B<--field>=([B<+>]I<number> | I<regexp>)
Compare values after a given number of whitespace separators,