X-Git-Url: http://git.shiar.nl/barcat.git/blobdiff_plain/9eb6da139e4958a8f31c03e62073f1a0f6e20898..28a07c68bc2845abab5506c7a088ff843eaba00f:/barcat diff --git a/barcat b/barcat index 0f0cfb8..bae7989 100755 --- a/barcat +++ b/barcat @@ -142,7 +142,6 @@ $opt{'graph-format'} //= '-'; $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'; @@ -211,13 +210,15 @@ if (defined $opt{interval}) { } 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}) { - ($valnum) = m/$opt{anchor} (\S*)/; - $valnum //= ''; + $valnum = m/$valmatch/ && $1; $uniq{$valnum}++ and next; push @values, $valnum; s/\A/\n /; @@ -535,9 +536,13 @@ or the I environment variable. =item B<-c>, B<--count> Omit repetitions and count the number of occurrences. -Similar to piping input to C +Similar to piping input through 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 | I) Compare values after a given number of whitespace separators,