$opt{anchor} = qr/$_/;
} or die $@ =~ s/(?:\ at\ \N+)?\Z/ for option $_[0]/r;
},
+ 'count|c!',
'human-readable|H!',
'sexagesimal!',
'reformat!',
$opt{'value-format'} ||= sub { sprintf '%.8g', $_[0] };
-my (@lines, @values, @order);
+my (@lines, @values, @order, %uniq);
$SIG{$_} = \&show_stat for $opt{'signal-stat'} || ();
$SIG{ALRM} = sub {
my $valmatch = qr< $opt{anchor} ( \h* -? $float |) >x;
while (defined ($_ = $opt{input} ? shift @{ $opt{input} } : readline)) {
s/\r?\n\z//;
+ if ($opt{count}) {
+ my ($valnum) = m/(\S*)/;
+ $valnum //= '';
+ $uniq{$valnum}++ and next;
+ push @lines, "\n " . $_;
+ push @values, $valnum;
+ next;
+ }
s/\A\h*// unless $opt{unmodified};
my $valnum = s/$valmatch/\n/ && $1;
push @values, $valnum;
my $limit = $opt{hidemax} ? $opt{hidemax}->($#lines, $nr) : $#lines;
+if ($opt{count}) {
+ $_ = $uniq{$_} for @values;
+ @order = @values;
+}
+
@order = sort { $b <=> $a } @order unless tied @order;
my $maxval = $opt{maxval} // (
$opt{hidemax} ? max grep { length } @values[$nr .. $limit] :
Options:
-a, --[no-]ascii Restrict user interface to ASCII characters
-C, --[no-]color Force colored output of values and bar markers
+ -c, --count Omit repetitions and count the number of
+ occurrences
-f, --field=([+]N|REGEXP)
Compare values after a given number of whitespace
separators
Can also be disabled by setting B<-M>
or the I<NO_COLOR> environment variable.
+=item B<-c>, B<--count>
+
+Omit repetitions and count the number of occurrences.
+Similar to piping input to C<sort | uniq -c>
+but keeping the order of first appearances.
+
=item B<-f>, B<--field>=([B<+>]I<number> | I<regexp>)
Compare values after a given number of whitespace separators,
ping google.com | barcat -f'time=\K' -t
-Commonly used after counting, for example users on the current server:
-
- users | tr ' ' '\n' | sort | uniq -c | barcat
-
-Letter frequencies in text files:
+Commonly used after counting, eg letter frequencies in text files:
cat /usr/share/games/fortunes/*.u8 |
perl -CS -nE 'say for grep length, split /\PL*/, uc' |
sort | uniq -c | barcat
+Users on the current server while preserving order:
+
+ users | tr ' ' '\n' | barcat -c
+
Number of HTTP requests per day:
cat httpd/access.log | cut -d\ -f4 | cut -d: -f1 | uniq -c | barcat