github.com/seeker-insurance/kit@v0.0.13/pretty/text/cmd/agg/doc.go (about)

     1  /*
     2  
     3  Agg computes aggregate values over tabular text.
     4  It behaves somewhat like the SQL “GROUP BY” clause.
     5  
     6  Usage:
     7  
     8  	agg [function...]
     9  
    10  It reads input from stdin as a sequence of records, one per line.
    11  It treats each line as a set of fields separated by white space.
    12  One field (the first, by default) is designated as the key.
    13  Successive lines with equal keys are grouped into a group,
    14  and agg produces one line of output for each group.
    15  (Note that only contiguous input lines can form a group.
    16  If you need to make sure that all records for a given key
    17  are grouped together, sort the input first.)
    18  
    19  For each remaining field,
    20  agg applies a function to all the values in the group,
    21  producing a single output value.
    22  The command line arguments specify which functions to use,
    23  one per field in the input table.
    24  
    25  Functions
    26  
    27  The available functions are:
    28  
    29      key        group by this field (default for field 1)
    30      first      value from first line of group (default for rest)
    31      last       value from last line of group
    32      sample     value from any line of group, uniformly at random
    33      prefix     longest common string prefix
    34      join:sep   concatenate strings with given sep
    35      smin       lexically least string
    36      smax       lexically greatest string
    37      min        numerically least value
    38      max        numerically greatest value
    39      sum        numeric sum
    40      mean       arithmetic mean
    41      count      number of records (ignores input value)
    42      const:val  print val, ignoring input
    43      drop       omit the column entirely
    44  
    45  The numeric functions skip items that don't parse as numbers.
    46  
    47  Examples
    48  
    49  Using the following input:
    50  
    51      $ cat >input
    52      -rwx   alice      100   /home/alice/bin/crdt
    53      -rw-   alice   210002   /home/alice/thesis.tex
    54      -rw-   bob      10051   /home/bob/expenses.tab
    55      -rwx   kr      862060   /home/kr/bin/blog
    56      -rwx   kr      304608   /home/kr/bin/agg
    57  
    58  Disk usage for each user, plus where that disk usage occurs
    59  (longest common prefix of filesystem paths):
    60  
    61      $ agg <input drop key sum prefix
    62      alice	210153	/home/alice/
    63      bob	10051	/home/bob/expenses.tab
    64      kr	1166668	/home/kr/
    65  
    66  Disk usage for executable vs non-executable files:
    67  
    68      $ sort input | agg key drop sum join:,
    69      -rw-	220053	/home/alice/thesis.tex,/home/bob/expenses.tab
    70      -rwx	1166768	/home/alice/bin/crdt,/home/kr/bin/agg,/home/kr/bin/blog
    71  
    72  */
    73  package main