freq

count frequencies of keys in text
git clone git://bvnf.space/freq.git
Log | Files | Refs | README

freq.1 (2053B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
.Dd "March 21, 2022"
.Dt FREQ 1
.Os "ben's space"
.Sh NAME
.Nm freq
.Nd count frequencies of keys in text
.Sh SYNOPSIS
.Nm
.Op Fl d Ar delim
.Op Fl k Ar key
.Op Ar file ...
.Sh DESCRIPTION
.Nm
counts the frequencies of each specified field for each line of text input from each
.Ar file .
For each line,
.Nm
checks the field at the specified
.Ar key
and increments the count for that value of the field.
The rest of the line is ignored.
.Pp
After checking every line, the counts for each value are printed, in the order
in which they are encountered for the first time.
The results are printed with the frequency, then a
.Aq tab
character, then the value of the field.
.Pp
The following options are supported:
.Bl -tag -width Ds
.It Fl d Ar delim
Set the field delimiter to the character
.Ar delim .
The default is any character of class
.Vt space
in the current locale (see
.Xr isspace 3 ) .
.It Fl k Ar key
Count the frequencies of the field found at position
.Ar key ,
where fields are separated by any number of
.Ar delim
characters.
The default value of
.Ar key
is 1, meaning that the first fields on each line are counted.
To use the whole line as a key, use the special value of 0.
If
.Ar key
fields are not found on a line, a warning is printed and the whole line is ignored.
.El
.Sh OPERANDS
.Bl -tag -width Ds
.It Ar file
A pathname of an input file.
If no
.Ar file
operand is specified, or if the
.Ar file
operand is
.Sq - ,
then standard input is used.
If
.Ar file
does not refer to a valid file, then the operand is ignored.
.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
For a file named
.Pa notes ,
containing the following data:
.Bd -literal -offset indent
I bought pears
You sold apples
I bought apples
I bought oranges
I sold bananas
You ate bananas
.Ed
.Pp
Below are some examples of various invocations of
.Nm
with their outputs:
.Bd -literal -offset indent
$ freq notes
4	I
2	You
.Ed
.Bd -literal -offset indent
$ freq -k 2 notes
3	bought
2	sold
1	ate
.Ed
.Sh SEE ALSO
.Xr cut 1 ,
.Xr sort 1
.Sh AUTHORS
.An phoebos Aq Mt ben@bvnf.space