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 are 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; optionally merges all files, printing all in parallel, one per column. 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 footer of five blank lines is also printed. With the `-f' option, a 3-line header is printed: the leading two blank lines are omitted; no footer used. The default page_length in both cases is 66 lines. The text line of the header takes up the full page_width in the form `yy-mm-dd HH:MM string Page nnnn'. String is a centered string.

Form feeds in the input cause page breaks in the output. Multiple form feeds produce empty pages.

Columns have equal width, separated by an optional string (default space). Lines will always be truncated to line width (default 72), unless you use the `-j' option. For single column output no line truncation occurs by default. Use `-w' option to truncate lines in that case.

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

`+first_page[:last_page]'
Begin printing with page first_page and stop with last_page. Missing `:LAST_PAGE' implies end of file. While estimating the number of skipped pages each form feed in the input file results in a new page. Page counting with and without `+first_page' is identical. By default, it starts with the first page of input file (not first page printed). Page numbering may be altered by `-N' option.
`-column'
With each single file, produce column-column output and print columns down. The column width is automatically estimated from page_width. This option might well cause some columns to be truncated. The number of lines in the columns on each page will be balanced. `-column' may not be used with `-m' option.
`-a'
With each single file, print columns across rather than down. column must be greater than one.
`-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 form feed instead of newlines to separate output pages. Default page length of 66 lines is not altered. But the number of lines of text per page changes from 56 to 63 lines.
`-h HEADER'
Replace the file name in the header with the centered string header. Left-hand-side truncation (marked by a `*') may occur if the total header line `yy-mm-dd HH:MM HEADER Page nnnn' becomes larger than page_width. `-h ""' prints a blank line header. Don't use `-h""'. A space between the -h option and the argument is always peremptory.
`-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).
`-j'
Merge lines of full length. Used together with the column options `-column', `-a -column' or `-m'. Turns off `-w' line truncation; no column alignment used; may be used with `-s[separator]'.
`-l page_length'
Set the page length to page_length (default 66) lines. If page_length is less than or equal 10 (and <= 3 with `-f'), the headers and footers are omitted, and all form feeds set in input files are eliminated, as if the `-T' option had been given.
`-m'
Merge and print all files in parallel, one in each column. If a line is too long to fit in a column, it is truncated (but see `-j'). `-s[separator]' may be used. Empty pages in some files (form feeds set) produce empty columns, still marked by separator. Completely empty common pages show no separators or line numbers. The default header becomes `yy-mm-dd HH:MM <blanks> Page nnnn'; may be used with `-h header' to fill up the middle part.
`-n[number-separator[digits]]'
Precede each column with a line number; with parallel files (`-m'), precede only 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). Default line counting starts with first line of the input file (not with the first line printed, see `-N').
`-N line_number'
Start line counting with no. line_number at first line of first page printed.
`-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[separator]'
Separate columns by a string separator. Don't use `-s separator', no space between flag and argument. If this option is omitted altogether, the default is a space, same as `-s" "'. With `-s' only, no separator is used, same as `-s""'. `-s' does not affect line truncation or column alignment.
`-t'
Do not print the usual header [and footer] on each page, and do not fill out the bottoms of pages (with blank lines or a form feed). No page structure is produced, but retain form feeds set in the input files. The predefined page layout is not changed. `-t' or `-T' may be useful together with other options; e.g.: `-t -e4', expand TAB in the input file to 4 spaces but do not do any other changes. Use of `-t' overrides `-h'.
`-T'
Do not print header [and footer]. In addition eliminate all form feeds set in the input files.
`-v'
Print unprintable characters in octal backslash notation.
`-w page_width'
Set the page width to page_width (default 72) characters. With/without `-w', header lines are always truncated to page_width characters. With `-w', text lines are truncated, unless `-j' is used. Without `-w' together with one of the column options `-column', `-a -column' or `-m', default truncation of text lines to 72 characters is used. Without `-w' and without any of the column options, no line truncation is used. That's equivalent to `-w 72 -j'.

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.