GNU text utilities - 8. Operating on fields within a line

Go to the first, previous, next, last section, table of contents.

# 8. Operating on fields within a line

## 8.1 `cut`: Print selected parts of lines

`cut` writes to standard output selected parts of each line of each input file, or standard input if no files are given or for a file name of ``-'`. Synopsis:

    cut [option]... [file]...

In the table which follows, the byte-list, character-list, and field-list are one or more numbers or ranges (two numbers separated by a dash) separated by commas. Bytes, characters, and fields are numbered from starting at 1. Incomplete ranges may be given: ``-m'` means ``1-m'`; ``n-'` means ``n'` through end of line or last field.

The program accepts the following options. Also see section 2. Common options.

``-b byte-list'`
``--bytes=byte-list'`
  Print only the bytes in positions listed in byte-list. Tabs and backspaces are treated like any other character; they take up 1 byte.
``-c character-list'`
``--characters=character-list'`
  Print only characters in positions listed in character-list. The same as ``-b'` for now, but internationalization will change that. Tabs and backspaces are treated like any other character; they take up 1 character.
``-f field-list'`
``--fields=field-list'`
  Print only the fields listed in field-list. Fields are separated by a TAB character by default.
``-d input_delim_byte'`
``--delimiter=input_delim_byte'`
  For ``-f'`, fields are separated in the input by the first character in input_delim_byte (default is TAB).
``-n'`
  Do not split multi-byte characters (no-op for now).
``-s'`
``--only-delimited'`
  For ``-f'`, do not print lines that do not contain the field separator character.
``--output-delimiter=output_delim_string'`
  For ``-f'`, output fields are separated by output_delim_string The default is to use the input delimiter.

## 8.2 `paste`: Merge lines of files

`paste` writes to standard output lines consisting of sequentially corresponding lines of each given file, separated by a TAB character. Standard input is used for a file name of ``-'` or if no input files are given.

Synopsis:

    paste [option]... [file]...

The program accepts the following options. Also see section 2. Common options.

``-s'`
``--serial'`
  Paste the lines of one file at a time rather than one line from each file.
``-d delim-list'`
``--delimiters delim-list'`
  Consecutively use the characters in delim-list instead of TAB to separate merged lines. When delim-list is exhausted, start again at its beginning.

## 8.3 `join`: Join lines on a common field

`join` writes to standard output a line for each pair of input lines that have identical join fields. Synopsis:

    join [option]... file1 file2

Either file1 or file2 (but not both) can be ``-'`, meaning standard input. file1 and file2 should be already sorted in increasing textual order on the join fields, using the collating sequence specified by the @env{LC_COLLATE} locale. Unless the ``-t'` option is given, the input should be sorted ignoring blanks at the start of the join field, as in `sort -b`. If the ``--ignore-case'` option is given, lines should be sorted without regard to the case of characters in the join field, as in `sort -f`.

The defaults are: the join field is the first field in each line; fields in the input are separated by one or more blanks, with leading blanks on the line ignored; fields in the output are separated by a space; each output line consists of the join field, the remaining fields from file1, then the remaining fields from file2.

The program accepts the following options. Also see section 2. Common options.

``-a file-number'`
  Print a line for each unpairable line in file file-number (either ``1'` or ``2'`), in addition to the normal output.
``-e string'`
  Replace those output fields that are missing in the input with string.
``-i'`
``--ignore-case'`
  Ignore differences in case when comparing keys. With this option, the lines of the input files must be ordered in the same way. Use ``sort -f'` to produce this ordering.
``-1 field'`
``-j1 field'`
  Join on field field (a positive integer) of file 1.
``-2 field'`
``-j2 field'`
  Join on field field (a positive integer) of file 2.
``-j field'`
  Equivalent to ``-1 field -2 field'`.
``-o field-list...'`
  Construct each output line according to the format in field-list. Each element in field-list is either the single character ``0'` or has the form m.n where the file number, m, is ``1'` or ``2'` and n is a positive field number. A field specification of ``0'` denotes the join field. In most cases, the functionality of the ``0'` field spec may be reproduced using the explicit m.n that corresponds to the join field. However, when printing unpairable lines (using either of the ``-a'` or ``-v'` options), there is no way to specify the join field using m.n in field-list if there are unpairable lines in both files. To give `join` that functionality, POSIX invented the ``0'` field specification notation. The elements in field-list are separated by commas or blanks. Multiple field-list arguments can be given after a single ``-o'` option; the values of all lists given with ``-o'` are concatenated together. All output lines -- including those printed because of any -a or -v option -- are subject to the specified field-list.
``-t char'`
  Use character char as the input and output field separator.
``-v file-number'`
  Print a line for each unpairable line in file file-number (either ``1'` or ``2'`), instead of the normal output.

In addition, when GNU `join` is invoked with exactly one argument, options ``--help'` and ``--version'` are recognized. See section 2. Common options.

Go to the first, previous, next, last section, table of contents.