Text and processing

The column command

Arranges text into aligned columns. With -t it turns messy output into a clean table.

Syntax

column [-t] [-s SEP] [archivo]Try it in the terminal →

Most useful options

-t, --tableWorks out how many columns the input has and draws an aligned table. It splits on whitespace unless you give another separator with -s
-s, --separator SEPCharacters that separate the input fields, for example : or , in a data file
-o, --output-separator SEPText placed between columns in the table. By default it is two spaces
-x, --fillrowsFills rows before columns, in the mode without -t
-S, --use-spaces NWithout -t, aligns with spaces instead of tabs, with at least N between columns. Only in recent versions of util-linux
-c, --output-width NMaximum output width in characters. With 0 or unlimited there is no limit, which is advisable when writing to a file
-R, --table-right COLUMNASRight-aligns the columns given by number, for example -R 2,3 for amounts

Copy-ready examples

$ printf 'a bb\nccc d\n' | column -tcreates an aligned table from two lines.

Example output

a    bb
ccc  d
$ printf 'nombre:edad\nana:31\nberto:4\n' | column -t -s :splits on colons, like a data file, and aligns.

Example output

nombre  edad
ana     31
berto   4
$ printf 'nombre:edad\nana:31\nberto:4\n' | column -t -s : -o ' | 'the same, with a bar between columns.

Example output

nombre | edad
ana    | 31
berto  | 4
$ printf 'lapiz 3\ngoma 12\n' | column -t -R 2right-aligns the second column, so the numbers line up.

Example output

lapiz   3
goma   12

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
column: nonexist: No such file or directoryThe file does not exist or the name is misspelled.Check the name with ls and run column again.
column: read failed: Is a directoryYou gave a directory. column only reads files and standard input.Give a file inside the folder, or use a pipe from ls.

Typical mistakes

  • Without -t, column only fills equal-width columns; it does not align by separators. For a table, use -t.
  • By default it splits on whitespace: a field with spaces inside gets cut. Use -s with the real separator, such as -s ':' or -s ','.
  • The default width is the terminal's, and in a file or a pipe it is 80 columns. With -c 0 there is no limit.

Differences from similar commands

  • printf: aligns with fixed widths you write in the format. column works out each column's width from the data.
  • awk: can align with printf inside a program, but you must write the width. column computes it on its own.

Related commands

FAQ

Is it the same as using tabs?

No: column computes each column's width and truly aligns them. With tabs, each line depends on the length of its words.

How do I add a header with column names?

With -N name1,name2 you give the names. If you do not want the header shown, add -d.

What happens to lines longer than the width?

By default they are not cut: the line comes out whole even if it passes the width. To trim a given column, use -T with its number.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course