Go to the first, previous, next, last section, table of contents.

Formatting file contents

These commands reformat the contents of files.

fmt: Reformat paragraph text

fmt fills and joins lines to produce output lines of (at most) a given number of characters (75 by default). Synopsis:

fmt [option]... [file]...

fmt reads from the specified file arguments (or standard input if none are given), and writes to standard output.

By default, blank lines, spaces between words, and indentation are preserved in the output; successive input lines with different indentation are not joined; tabs are expanded on input and introduced on output.

fmt prefers breaking lines at the end of a sentence, and tries to avoid line breaks after the first word of a sentence or before the last word of a sentence. A sentence break is defined as either the end of a paragraph or a word ending in any of `.?!', followed by two spaces or end of line, ignoring any intervening parentheses or quotes. Like TeX, fmt reads entire "paragraphs" before choosing line breaks; the algorithm is a variant of that in "Breaking Paragraphs Into Lines" (Donald E. Knuth and Michael F. Plass, Software--Practice and Experience, 11 (1981), 1119--1184).

The program accepts the following options. Also see section Common options.

`-c'
`--crown-margin'
Crown margin mode: preserve the indentation of the first two lines within a paragraph, and align the left margin of each subsequent line with that of the second line.
`-t'
`--tagged-paragraph'
Tagged paragraph mode: like crown margin mode, except that if indentation of the first line of a paragraph is the same as the indentation of the second, the first line is treated as a one-line paragraph.
`-s'
`--split-only'
Split lines only. Do not join short lines to form longer ones. This prevents sample lines of code, and other such "formatted" text from being unduly combined.
`-u'
`--uniform-spacing'
Uniform spacing. Reduce spacing between words to one space, and spacing between sentences to two spaces.
`-width'
`-w width'
`--width=width'
Fill output lines up to width characters (default 75). fmt initially tries to make lines about 7% shorter than this, to give it room to balance line lengths.
`-p prefix'
`--prefix=prefix'
Only lines beginning with prefix (possibly preceded by whitespace) are subject to formatting. The prefix and any preceding whitespace is stripped for the formatting and then re-attached to each formatted output line. One use is to format certain kinds of program comments, while leaving the code unchanged.

pr: Paginate or columnate files for printing

pr writes each file (`-' means standard input), or standard input if none are given, to standard output, paginating and optionally outputting in multicolumn format. Synopsis:

pr [option]... [file]...

By default, a 5-line header is printed: two blank lines; a line with the date, the file name, and the page count; and two more blank lines. A five line footer (entirely) is also printed.

Form feeds in the input cause page breaks in the output.

The program accepts the following options. Also see section Common options.

`+page'
Begin printing with page page.
`-column'
Produce column-column output and print columns down. The column width is automatically decreased as column increases; unless you use the `-w' option to increase the page width as well, this option might well cause some input to be truncated.
`-a'
Print columns across rather than down.
`-b'
Balance columns on the last page.
`-c'
Print control characters using hat notation (e.g., `^G'); print other unprintable characters in octal backslash notation. By default, unprintable characters are not changed.
`-d'
Double space the output.
`-e[in-tabchar[in-tabwidth]]'
Expand tabs to spaces on input. Optional argument in-tabchar is the input tab character (default is TAB). Second optional argument in-tabwidth is the input tab character's width (default is 8).
`-f'
`-F'
Use a formfeed instead of newlines to separate output pages.
`-h header'
Replace the file name in the header with the string header.
`-i[out-tabchar[out-tabwidth]]'
Replace spaces with tabs on output. Optional argument out-tabchar is the output tab character (default is TAB). Second optional argument out-tabwidth is the output tab character's width (default is 8).
`-l n'
Set the page length to n (default 66) lines. If n is less than 10, the headers and footers are omitted, as if the `-t' option had been given.
`-m'
Print all files in parallel, one in each column.
`-n[number-separator[digits]]'
Precede each column with a line number; with parallel files (`-m'), precede each line with a line number. Optional argument number-separator is the character to print after each number (default is TAB). Optional argument digits is the number of digits per line number (default is 5).
`-o n'
Indent each line with n (default is zero) spaces wide, i.e., set the left margin. The total page width is `n' plus the width set with the `-w' option.
`-r'
Do not print a warning message when an argument file cannot be opened. (The exit status will still be nonzero, however.)
`-s[c]'
Separate columns by the single character c. If c is omitted, the default is space; if this option is omitted altogether, the default is TAB.
`-t'
Do not print the usual 5-line header and the 5-line footer on each page, and do not fill out the bottoms of pages (with blank lines or formfeeds).
`-v'
Print unprintable characters in octal backslash notation.
`-w n'
Set the page width to n (default is 72) columns.

fold: Wrap input lines to fit in specified width

fold writes each file (`-' means standard input), or standard input if none are given, to standard output, breaking long lines. Synopsis:

fold [option]... [file]...

By default, fold breaks lines wider than 80 columns. The output is split into as many lines as necessary.

fold counts screen columns by default; thus, a tab may count more than one column, backspace decreases the column count, and carriage return sets the column to zero.

The program accepts the following options. Also see section Common options.

`-b'
`--bytes'
Count bytes rather than columns, so that tabs, backspaces, and carriage returns are each counted as taking up one column, just like other characters.
`-s'
`--spaces'
Break at word boundaries: the line is broken after the last blank before the maximum line length. If the line contains no such blanks, the line is broken at the maximum line length as usual.
`-w width'
`--width=width'
Use a maximum line length of width columns instead of 80.

Go to the first, previous, next, last section, table of contents.