count duplicates anchored by specified field
[barcat.git] / barcat
diff --git a/barcat b/barcat
index 3b73b675192497780af97c4a7cf113aa858349d0..9a19d02a2c141529c3ddb5cbd875e9027649986c 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -210,11 +210,11 @@ if (defined $opt{interval}) {
 }
 
 my $float = qr<[0-9]* [.]? [0-9]+ (?: e[+-]?[0-9]+ )?>; # positive numberish
-my $valmatch = qr< $opt{anchor} ( \h* -? $float |) >x;
+my $valmatch = qr< $opt{anchor} ( \h* -? $float |) >;
 while (defined ($_ = $opt{input} ? shift @{ $opt{input} } : readline)) {
        s/\r?\n\z//;
        if ($opt{count}) {
-               my ($valnum) = m/(\S*)/;
+               my ($valnum) = m/$opt{anchor} (\S*)/;
                $valnum //= '';
                $uniq{$valnum}++ and next;
                push @lines, "\n " . $_;
@@ -776,7 +776,7 @@ Users on the current server while preserving order:
 
 Number of HTTP requests per day:
 
-    cat httpd/access.log | cut -d\  -f4 | cut -d: -f1 | uniq -c | barcat
+    barcat -cf'\[([^:]+)' httpd/access.log
 
 Any kind of database query results, preserving returned alignment: