NAME
table
—
Command line utility to format and
display CSV and TSV
SYNOPSIS
table |
-h | --help |
-V | --full-version |
-v | --version |
table |
[-a alignment |
--align= alignment]
[-b | --border-mode ]
[-c cols |
--columns= cols]
[-D | --align-dot ]
[-d delim |
--delimiter= delim]
[-f format |
--format= format]
[-H | --align-header ]
[-m | --msdos ]
[-n | --no-ansi ]
[-p | --pause ]
[-q behavior |
--quotes= behavior]
[-s set |
--symbols= set]
[-t | --expand-tabs ]
[-y | --yes-ansi ]
[pathname] |
COMMAND ALIASES
tablep |
is a synonym for ‘table -p ’. |
tsvtable |
is a synonym for ‘table -d "$(printf
'\t')" -q ignore ’. |
DESCRIPTION
table
is a command line utility to format
and display CSV and TSV. It parses the file given by
pathname or standard input and prints out a table
representing its contents using Unicode characters for box drawing.
When specifying multiple pathname arguments,
table
prints a warning to stderr. Only the first
such argument is processed. If pathname is omitted,
table
reads standard input.
-a
alignment,--align=
alignment- Set column alignments. alignment is a string
consisting of characters
l
,c
orr
, which respectively set the alignment of the corresponding column to left, center or right. For example,-a
rccc
sets the alignment for the first column to right, and the next three columns to center. -b
,--border-mode
- Border mode: force single column.
-c
cols,--columns=
cols- Set maximum table width in columns (default 80).
-D
,--align-dot
- Set alignment character to dot “.” instead of a space “ ”.
-d
delim,--delimiter=
delim- Set field delimiter (default “,”). First line of the input
determines the number of table columns. The first character of
delim becomes the delimiter. Special characters,
like “;”,need to be quoted or escaped:
or
$ table -d';'
In the examples above, “'” and “\” are parsed by the shell and are not passed to$ table -d\;
table
, so are not considered as “first characters” for the assignment.Note that the
-b
parameter takes precedence: if it is present,-d
is ignored. -f
format,--format=
format- Set widths for individual columns as ratio. Parameter
format should be a string of weights separated by
colons. For example:
$ table -c 50 -s aa examples/quotes-english.csv +-----------+-----------+-----------+-----------+ |ID |Name |Surname |Age | |001 |John |Smith |34 | |002 |Steven |Watson |23 | |003 |Richard |Smith |33 | |007 |Bond, James|Bond |46 | +-----------+-----------+-----------+-----------+ $ table -f 1:2:3:4 -c 50 -s aa examples/quotes-english.csv +----+---------+-------------+------------------+ |ID |Name |Surname |Age | |001 |John |Smith |34 | |002 |Steven |Watson |23 | |003 |Richard |Smith |33 | |007 |Bond, Jam|Bond |46 | +----+---------+-------------+------------------+ $ table -f 1:5:5:1 -c 50 -s aa examples/quotes-english.csv +----+------------------+------------------+----+ |ID |Name |Surname |Age | |001 |John |Smith |34 | |002 |Steven |Watson |23 | |003 |Richard |Smith |33 | |007 |Bond, James |Bond |46 | +----+------------------+------------------+----+
-H
,--align-header
- Makes the column alignment also apply to header row. The default behavior is to print header cells left-aligned.
-h
,--help
- Print the usage information screen.
-m
,--msdos
- Ignore carriage return (\r) characters in input. The default behavior is to treat them as part of the text, which can produce unexpected results.
-n
,--no-ansi
- Turn off ANSI SGR codes in the output. By default, the header row is printed in bold using ANSI codes if the stdout is a tty. This switch prevents that.
-p
,--pause
- Presents the message “Press Enter to continue” and waits for
input after outputting the table. This accounts for executing
table
from file managers which don't pause after executing programs or as a single command from terminal emulators. -q
behavior,--quotes=
behavior- behavior can be one of the following:
process
- Treats everything between the quotes as a single column. Treats consecutive quotes within the quoted text as literal quotes. This is the default.
ignore
- Ignores the special meaning of quotes (like TSV). This is the default
if
table
is called astsvtable
.
-s
set,--symbols=
set- Use table symbol set set for table lines, where
set is one of the following (format:
⟨border⟩⟨inner
border⟩):
Literal Meaning aa
ascii-ascii, ae
ascii-empty, dd
double-double, ds
double-single (default), de
double-empty, ea
empty-ascii, ed
empty-double, ee
empty-empty, es
empty-single, sd
single-double, se
single-empty, ss
single-single. Any other value for set will produce an error.
-t
,--expand-tabs
- Expand tabs to spaces, honoring standard modulo 8 tab stops. Default
behavior is to output tab characters as-is.
Note that the
-d
parameter takes precedence, unless-b
is also used: if the delimiter is set to the TAB character (0x09),-t
is ignored. When-b
is used in addition,-t
is honored and-d
ignored. -V
,--full-version
- Print full version (like
-v
), followed by copyright notice, and exit. -v
,--version
- Print program version and commit date, and exit.
-y
,--yes-ansi
- Explicitly turn on ANSI SGR codes in the output. By default, the header row is printed in bold using ANSI codes, unless the stdout is not a tty. This switch enforces the output of ANSI SGR codes, even in that case.
EXIT STATUS
The table
utility exits 0 on
success, and >0 if an error occurs.
EXAMPLES
- Periodically display CPU load information in a single-line table (requires
a mounted Linux-style /proc file system and GNU
watch(1))
$ watch "table /proc/loadavg -d ' ' -c 50 -n -s ss"
- Format a long list of files in the current directory in a double line
table with single-line column divisors
$ LC_ALL=C ls -l | tail -n +2 | sed -E 's/ +/ /g' | table -d ' ' -n
Caution: format of ls(1) is not standardized, so this example might not work as intended.
- Print information from /etc/passwd in a table:
$ table -n -d : -f 3:1:1:1:4:4:4 /etc/passwd
- Same as above, without borders and with different column alignment:
$ table -n -H -d: -arccclll -see -f3:1:1:1:4:4:4 /etc/passwd
SEE ALSO
AUTHORS
Strahinya Radich <sr@strahinja.org>, 2020-2024
BUGS
Bugs can be reported using the ticket tracker at: https://todo.sr.ht/~strahinja/table