pr
The pr command takes a text file and splits it into
pages of text separated by a number of newlines with a header on each
page. Optionally, it can add a form feed character between the pages
for sending the output directly to a printer.
For example, using the command with no options:
user@bible:~ > pr README.txt
will output pages with a header on each looking like this:
2004-08-10 12:26 INDEX Page 1
fold
The fold command reformats a text file by breaking long lines.
By default, the lines will be set to a maximum width of 80 characters.
You can set the width of the lines you want in the output with the
option - w, but if this is too small, the output may look bad.
A case where the fold command is useful is when you have saved
a word processor document as plain text. In the text file, each
paragraph will be a single line.
A command such as fold - w 7 6 file.txt will break these lines sensibly.
fmt
The fmt command takes some text (say an article that you have
written in a text editor) and does some sensible reformatting to it.
Provided that you have separated paragraphs by empty lines, fmt will
combine broken lines and make all lines asensible length.
It
can also ensure that words are separated by one space and sentences by
two. In the example that follows, the -u option forces uniform spacing—
in other words, one space between words and two spaces between
sentences.
user@bible:~ > cat badfile
This is a
file with some extra space and its line endings are in a
mess. We
need to
reformat it somehow.
user@bible:~ > fmt –u badfile
This is a file with some extra space and its line endings in a mess. We
need to reformat it somehow.
groff -Tascii
The document formatting system groff is used by the man page system to
create formatted man pages (which are written in plain text with
markup) from their source. It can also produce nicely formatted printed
output.
This is not the place to talk about groff in general. However, you may
have seen those nicely justified text files with a straight right-hand
margin and wondered how they are produced. The same effect is seen in
man pages, and this is no accident because you can use groff (which is
used to format man pages) with the -Tascii option to produce text
formatted in that way.
It adds spaces to reduce the need for
splitting words and hyphenation, and hyphenates reasonably sensibly.
The output certainly looks nice, and if you are writing a file that
will be read in text format (for
example, a long README file to distribute with some software), it gives a nice impression to format it in this way.
user@bible:~ > groff –Tascii filename
a2ps
The a2ps command converts a text file to PostScript and either creates a file or sends it to the printer. If you simply type a2ps file ,
the file will be printed with a nice header and footer showing the
filename and datestamp, the name of the user who printed it, and the
date of printing.
You can control the way a2ps works with a huge variety of options; for example, this command:
a2ps -j -B -R --columns=1 file -o outfile.ps
creates a PostScript file outfile.ps showing the text of the original
file, and with a nice border around the page (the -j option), but no
other header or footer. (The headers are suppressed by -B , while -R forces portrait format. The -o option specifies the output file.)
enscript
The enscript command does the same thing as a2ps. The default
output from a2ps looks nicer. However, enscript has some other clever
capabilities, including adding syntax highlighting to code in certain
languages, and also producing output in HTML and RTF formats. For a
list of all the options, see the man page.