29.7 Count How Many Times Each Word Is Used
Here's this book's Preface run through wordfreq :
% The script was taken from a long-ago Usenet ( 1.33 ) posting by Carl Brandauer. Here is Carl's original script (with a few small edits):
The version on the disc is somewhat different. It adjusts the tr commands for the script's -i option. The disc version also doesn't use pr to make output in four columns, though you can add that to your copy of the script - or just pipe the wordfreq output through pr on the command line when you need it.
The second
tr
command above (with the
tr -cs "[a-z]'" "[\012*]" If you aren't sure which version of tr you have, see article 35.11 . You could use deroff ( 29.10 ) instead.
One of the beauties of a simple script like this is that you can
tweak it if you don't like the way it counts.
For example, if you want hyphenated words like
copy-editor
to count as one, add a hyphen to the - , |
|