NAME

freqtable - Print frequency table of lines/words/characters/bytes/numbers

VERSION

This document describes version 0.004 of freqtable (from Perl distribution App-freqtable), released on 2020-10-19.

SYNOPSIS

% freqtable [OPTIONS] < INPUT

Sample input:

% cat input-lines.txt
one
one
two
three
four
five
five
five
six
seven
eight
eight
nine

% cat input-words.txt
one one two three four five five five six seven eight eight nine

% cat input-nums.txt
9.99 cents
9.99 dollars
9 cents

Modes

Display frequency table (by default: lines):

% freqtable input-lines.txt
3       five
2       eight
2       one
1       four
1       nine
1       seven
1       six
1       three
1       two

Display frequency table (words):

% freqtable -w input-words.txt
3       five
2       eight
2       one
1       four
1       nine
1       seven
1       six
1       three
1       two

Display frequency table (characters):

% freqtable -c input-words.txt
12
12      e
 7      i
 5      n
 4      f
 4      o
 4      t
 4      v
 3      h
 2      g
 2      r
 2      s
 1

 1      u
 1      w
 1      x

Display frequency table (nums):

% freqtable -n input-nums.txt
2      9.99
1      9

Display frequency table (integers):

% freqtable -i input-nums.txt
3      9

-F option

Don't display the frequencies:

% freqtable -F input-lines.txt
five
eight
one
four
nine
seven
six
three
two

Filter by frequencies

Only display lines that appear three times:

% freqtable -F input-lines.txt --freq 3
3       five

Only display lines that appear more than once:

% freqtable -F input-lines.txt --freq 2-
3       five
2       eight
2       one

Only display lines that appear less than three times:

% freqtable -F input-lines.txt --freq -2
2       eight
2       one
1       four
1       nine
1       seven
1       six
1       three
1       two

DESCRIPTION

This utility counts the occurences of lines (or words/characters) in the input then display each unique lines along with their number of occurrences. You can also instruct it to only show lines that have a specified number of occurrences.

You can use the following Unix command to count occurences of lines:

% sort input-lines.txt | uniq -c | sort -nr

and with a bit more work you can also use a combination of existing Unix commands to count occurrences of words/characters, as well as filter items that have a specified number of occurrences; freqtable basically offers convenience.

EXIT CODES

0 on success.

255 on I/O error.

99 on command-line options error.

OPTIONS

  • --bytes, -c

  • --chars, -m

  • --words, -w

  • --lines, -l

  • --number, -n

    Treat each line as a number. A line like this:

    9.99 cents

    will be regarded as:

    9.99
  • --integer, -i

    Treat each line as an integer. A line like this:

    9.99 cents

    will be regarded as:

    9
  • --ignore-case, -f

  • --no-print-freq, -F

    Will not print the frequencies.

  • --freq=s

    Filter by frequencies. N (e.g. --freq 5) means only display items that occur N times. M-N (e.g. --freq 5-10) means only display items that occur between M and N times. M- (e.g. --freq 5-) means only display items that occur at least M times. -N (e.g. --freq -10) means only display items that occur at most N times.

FAQ

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-freqtable.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-freqtable.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-freqtable

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Unix commands wc, sort, uniq

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020, 2018 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.