home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 43.7 Quick-and-Dirty Formatting Before Printing Chapter 43
Printing
Next: 43.9 Indenting Text for Printing
 

43.8 Fixing Margins with pr and fold

The System V version of pr ( 43.7 ) has a -F option for folding lines that are too wide for the output page: the printer won't truncate them. If you print lots of random data and stuff that may have long lines and your pr doesn't have -F , try the fold command instead.

fold arbitrarily breaks lines that are too long, by default at 80 columns. Use - width where width is the desired column to fold at for some other breaking point.

I made an alias ( 10.2 ) and shell function ( 10.9 ) called prF to do that. It prints a single file and puts the filename in the pr heading (usually, if you pipe to pr , it won't know the filename). You might want to add |   lpr onto the end of this, too:


alias prF 'fold \!^ | pr -h "\!^"'

csh_init
sh_init
A good way to see which lines are folded is with line numbering. pr versions without -F usually don't have -n either. You can add it to your alias with cat -n ( 25.21 ) . The lines will be numbered before they're folded:

alias prnF 'cat -n \!^ | fold | pr -h "\!^"'

To shorten lines by folding them after a word near the right-hand end (instead of at some particluar column), try fmt ( 35.2 ) .

- JP


Previous: 43.7 Quick-and-Dirty Formatting Before Printing UNIX Power Tools Next: 43.9 Indenting Text for Printing
43.7 Quick-and-Dirty Formatting Before Printing Book Index 43.9 Indenting Text for Printing

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System