LinuxCommandLibrary

col

Filter out reverse line feeds

TLDR

Filter reverse line feeds from input

$ [command] | col
copy

Filter reverse line feeds and output with spaces instead of tabs
$ [command] | col [[-x|--spaces]]
copy

Remove backspaces, output only the last character written to each position
$ [command] | col [[-b|--no-backspaces]]
copy

Specify a buffer size with a specific number of lines
$ [command] | col [[-l|--lines]] [num]
copy

Format a manual page for viewing with less
$ man ls | col [[-b|--no-backspaces]] | less
copy

Process a file with reverse line feeds and save the cleaned output
$ cat [path/to/input_file] | col [[-x|--spaces]] > [output_file]
copy

SYNOPSIS

col [-bfhpx] [file ...]

PARAMETERS

-b
    Do not split long lines (default splits lines longer than 2048 characters)

-f
    Permit forward half-line feeds; split lines only on forward half-line to next line, eliminate backward feeds

-h
    Convert spaces to tabs where multiple spaces follow a tab stop

-p
    Pass unknown control characters unchanged (normally escaped)

-x
    Output multiple spaces instead of tabs even with -h; assume terminal handles overstrike

DESCRIPTION

col is a Unix filter utility designed to process output from text formatters like nroff, troff, tbl, and eqn, converting reverse line feeds (half-line upward motions) into printable form suitable for line printers or terminals lacking support for such features.

Reverse line feeds, often produced by backspaces (^H or \b) combined with carriage returns, simulate effects like underlining and bold by overstriking characters. col translates these into forward motions: half-line feeds become full lines, backspaces overlay characters appropriately, and trailing blanks are handled to avoid artifacts.

Without col, such output appears garbled on devices without reverse-motion hardware. It reads from standard input or files, writing cleaned text to stdout, making it ideal for pipelines, e.g., formatting man pages for printing.

Key behaviors include line splitting for very long lines (>2048 chars) unless suppressed, and conservative handling of unknown controls to prevent corruption. Widely used historically, it remains relevant for legacy typesetting workflows.

CAVEATS

Handles classic nroff/troff output best; may alter modern terminal escape sequences. Long lines buffered internally; very wide input risks truncation. Not UTF-8 aware in all implementations.

EXAMPLES

nroff -man foo.1 | col -b | lpr
Formats and prints man page.

tbl file | col -h > output.txt
Processes table with space-to-tab optimization.

HISTORY

Originated in early AT&T Unix (PWB 1.0, circa 1977); refined in 4.3BSD (1986). Now in util-linux package on Linux, with minor POSIX compliance variations across systems.

SEE ALSO

nroff(1), troff(1), tbl(1), ul(1), expand(1)

Copied to clipboard