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


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 43.8 Fixing Margins with pr and fold Chapter 43
Printing
Next: 43.10 Filename Headers Above Files Without pr
 

43.9 Indenting Text for Printing

If you want to print a file that has plain text (not PostScript or some other page description language), you can indent the printout by adding some spaces to the start of each line. Use sed (34.24 ) to add a TAB or two (if your printer can handle TABs) - otherwise, spaces - to the start of each line. Here's a simple command that adds four spaces to the start of each line of the logdata file, then prints with lpr :

% sed 's/^/    /' logdata | lpr

You'll run into trouble if the file you're printing has any TABs in it though, because the extra spaces at the start of each line can mess up the tabstops. In that case, expand tabs (41.4 ) first:

% expand logdata | sed 's/^/    /' | lpr

The pr (43.7 ) command makes a nicely formatted printout. You can indent its output, too. If your pr doesn't have a -o (offset) switch, though, pipe its output through sed :

% pr logdata | sed 's/^/    /' | lpr

That doesn't always work. If there are TABs in the file, pr may not expand them - though some versions of pr have a -e switch to do that. Also, your indentation will indent the heading on each page - too much indentation can shove the heading off the right-hand side of the paper. Here's a better command to handle those problems. It expands the TABs and indents the body but doesn't indent the heading:

% expand logdata | sed 's/^/    /' | pr -h logdata | lpr

The -h  logdata puts the filename at the top of each page (because pr can't get the name otherwise). Omit that if you don't want it.

The offset (35.7 ) script lets you set the indentation with a command-line option.

- JP


Previous: 43.8 Fixing Margins with pr and fold UNIX Power Tools Next: 43.10 Filename Headers Above Files Without pr
43.8 Fixing Margins with pr and fold Book Index 43.10 Filename Headers Above Files Without pr

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