col
Filter out reverse line feeds
SYNOPSIS
col [OPTION]... [FILE]...
PARAMETERS
-b, --no-backspaces
Filter out backspace characters. This option causes multiple characters at the same position to be overwritten, resulting in only the last character printed at that position being visible.
-f, --spaces
Permit forward half-line motions (for superscripts and subscripts), which are otherwise discarded. This option makes col preserve multiple spaces, which can lead to wider output.
-h, --no-halfspaces
Discard forward half-line motions and back-half line motions. This is the default behavior.
-l
Buffer at most N lines. By default, no line limit is applied. If this limit is exceeded, col may truncate input or produce corrupted output.
-x, --expand-tabs
Expand tabs to multiple space characters. Without this option, col attempts to preserve tabs where possible.
--help
Display a help message and exit.
--version
Output version information and exit.
FILE...
One or more input files to process. If no files are specified, col reads from standard input.
DESCRIPTION
The col command acts as a filter, primarily designed to process text containing control sequences that manipulate cursor movement, such as reverse line feeds, half-line motions, and backspaces. These sequences are commonly generated by text formatting systems like nroff or troff (often used by man pages) to create effects like bolding or underlining on character-based terminals.
col reads its standard input (or specified files) and outputs the processed text to standard output. It maintains a virtual screen buffer, simulating the behavior of a terminal, and resolves overlapping characters or cursor movements by determining the final character at each virtual position. For instance, it can resolve character overstrikes (e.g., '_' followed by a backspace and 'c' to form an underlined 'c') into a simpler, printable string. Its main purpose is to convert complex terminal-specific formatting into a linear stream of characters, suitable for programs like lpr (for printing) or pr (for pagination), ensuring that formatted text displays correctly on devices that do not interpret these control sequences.
CAVEATS
The col command is primarily designed for processing text generated by traditional Unix text formatting tools like nroff or troff. While it handles common ASCII control sequences effectively, its behavior with complex Unicode characters, multi-byte sequences, or modern terminal escape codes (e.g., ANSI color codes) may be inconsistent or lead to unintended formatting. It processes input character by character, which can sometimes result in less-than-optimal output for highly structured or graphically oriented text.
It's generally not needed for modern pagers like less or more which can interpret nroff sequences directly. Its main utility is when piping to simpler tools or printers that do not handle such sequences natively.
TYPICAL USAGE
The col command is often implicitly invoked by the man command to format manual pages for display. Users can also pipe output from other commands to col to clean up text before printing or further processing. For example, nroff -man mydoc.n | col -b | lpr would format 'mydoc.n' as a man page, remove backspaces, and then print it.
HISTORY
The col command has been a standard utility in Unix-like operating systems since their early days, originating from AT&T Bell Labs Unix and later becoming part of BSD and System V. Its development was directly tied to the need to render formatted text (especially from nroff and troff) correctly on line printers and character-based terminals. Over time, it was incorporated into various utility sets, including util-linux for Linux systems. While its core function remains consistent, modern terminal emulators and pagers often handle many of the same control sequences, reducing the direct need for col in interactive viewing, but it remains valuable for scripting and printing pipelines.