Col

From LQWiki
Jump to: navigation, search

col is a filter to alter a stream of formatted text to remove reverse line-feeds (and half-reverse line-feeds) that appear in the outputs of some commands, reorganizing the data so that only forward line-motions are used. It also alters the way in which text is displayed in the presence of carriage-return, tab, space and backspace characters in various ways depending on command-line options. Other control character sequences may be dropped or retained, again depending on command-line options. It buffers the data to support the reorganization.

All of this is affected by the LANG, LC_ALL and LC_CTYPE environment variables.

options

-b Do not output backspaces or carriage-returns, retaining only the last character written to each column position.
-h Do not convert tabs to multiple spaces (this is also the default).
-x Convert tabs to multiple spaces.
-p Preserve unknown control-sequences (the default is to discard them.)
-f "fine" mode. Forward half linefeeds are allowed. Without this option, additional lines may appear just to contain subscripts or superscripts.

control characters

col understands these control characters (with an equivalent bash echo-command argument assuming the -E option to echo)

  • ESC-7 "\e7" reverse line feed
  • ESC-8 "\e8" half-reverse line feed
  • ESC-9 "\e9" half-forward line feed
  • BS "\b" backspace; moves back one column but not beyond the left margin
  • CR "\r" carriage-return; moves back to the left margin without advancing to the next line
  • NL or
  • LF "\n" forward line-feed a.k.a. newline. Also returns to column 1.
  • SI "\017" shift in to normal character set
  • SO "\016" shift out to alternate character set (mostly obsolete since the advent of UNICODE)
  • SP " " normal space
  • TAB "\t" horizontal tab, spaces at least one character to the right, up to a tab stop
  • VT "\v" vertical tab, interpreted by col as a reverse line-feed for backwards compatibility with some earlier software. (Actual vertical tabbing applied mainly to continuous-form printing on fan-fold paper.)

Use

Originally designed to be used in connection with the nroff formatting command, it is also useful for filtering out the prolix progress bars and meters of programs such as ntfsclone.

History

The col filter appeared in Version 6 AT&T Unix.
In Debian and derivatives, col is usually part of a package named bsdmainutils, making it likely that it was cloned by the BSD project.
A more recent standard appeared in Version 2 of the Single UNIX Specification ("SUSv2"), marked as LEGACY and is omitted in later versions.

Provided by

Most (all?) Linux distributions incorporate this from the [util-linux] project.

See Also