Alfarebis

Musings on informatics, language, music...

Print word list more efficiently

If you want to print a long list of words, it is better to format the word list into columns, otherwise you will print out one column pages, thus wasting a lot of paper. The command pr can be a helpful tool.


Suppose you want to print out all English words starting with shr, you will end up with a list of 86 words, as illustrated on the following lines.

The regular expression (grep) selects all words from the british-english dictionary on Ubuntu, matching the combination "^s[^aeiouy]": i.e. a word starting in s followed by a character which is not a vowel, followed by r. Apparently, there are four combinations possible: scr, shr, spr and str:

$ grep ^s[^aeiouy]r /usr/share/dict/british-english | 
  cut -c1-3 | sort | uniq -c 
    204 scr
     86 shr
    109 spr
    358 str

If we want to print out even the smallest set of 86 shr words, you get two pages of one column. However, the tool pr will give better results.

In the following pipeline, pr uses 10 lines per sheet (-l 20, including header and footer lines), three columns (-3), and each item is numbered (-n). The extra commands reduce the extra page lines (tr) and the default tab-chars between the columns are replaced by blank chars (expand). Finally, pagination (lines starting with 2020) are replaced by a blank line.

$ grep ^shr /usr/share/dict/british-english | pr -l 20 -3 -n | 
  tr -s '\n' | expand | sed 's/^2020.*//' 

     1   shrank             11   shreds             21   shrews
     2   shrapnel           12   shrew              22   shriek
     3   shrapnel's         13   shrew's            23   shriek's
     4   shred              14   shrewd             24   shrieked
     5   shred's            15   shrewder           25   shrieking
     6   shredded           16   shrewdest          26   shrieks
     7   shredder           17   shrewdly           27   shrift
     8   shredder's         18   shrewdness         28   shrift's
     9   shredders          19   shrewdness's       29   shrike
    10   shredding          20   shrewish           30   shrike's

    31   shrikes            41   shrimp             51   shrinkable
    32   shrill             42   shrimp's           52   shrinkage
    33   shrilled           43   shrimped           53   shrinkage's
    34   shriller           44   shrimping          54   shrinking
    35   shrillest          45   shrimps            55   shrinks
    36   shrilling          46   shrine             56   shrive
    37   shrillness         47   shrine's           57   shrived
    38   shrillness's       48   shrines            58   shrivel
    39   shrills            49   shrink             59   shrivelled
    40   shrilly            50   shrink's           60   shrivelling

    61   shrivels           70   shrove             79   shrubs
    62   shriven            71   shrub              80   shrug
    63   shrives            72   shrub's            81   shrug's
    64   shriving           73   shrubberies        82   shrugged
    65   shroud             74   shrubbery          83   shrugging
    66   shroud's           75   shrubbery's        84   shrugs
    67   shrouded           76   shrubbier          85   shrunk
    68   shrouding          77   shrubbiest         86   shrunken
    69   shrouds            78   shrubby

If you want the result in pdf-format, send the result to a text file, then use a tool (for example, soffice) to convert the text file to pdf file:

 $ grep ^shr /usr/share/dict/british-english | pr -l 20 -3 -n | 
   tr -s '\n' | expand | sed 's/^2020.*//' > words-shr.txt
 $ soffice --convert-to "pdf" words-shr.txt

The result is stored in words-shr.pdf.

Tags: linux, pr, expand, soffice, pdf