paste

Updated: October 26, 2022

Merge lines of given input files, and write the resulting lines to standard output (POSIX)

Syntax:

paste [-s] [-d list] file

Runs on:

QNX Neutrino

Options:

-d list
Specifies that each character in the list is an element specifying a delimiter character. Unless a backslash character appears in list, each character in list is an element specifying a delimiter character. If a backslash character appears in list, the backslash character and one or more characters following it are an element specifying a special delimiter character, described below. These elements specify one or more delimiters to use, instead of the default tab, to replace the newline of the input lines. If the -s option is also specified:
  • The last <newline> in a file isn't modified.
  • The delimiter is reset to the first element of the list after each file operand is processed.

If the -s option isn't specified:

  • The <newline>s in the file specified by the last file operand can't be modified.
  • The delimiter is reset to the first element of the list each time a line is processed from each file.

When a backslash character appears in list, the backslash character and the other characters that follow it are used to represent these delimiter characters:

  • \n represents a <newline>
  • \t represents a <tab>
  • \\ represents a backslash character
  • \0 represents an empty string, not a NULL character. If a lower case or upper case “x” immediately follows \0, or any character defined by the LC_CTYPE digit keyword, the results are undefined. For more information, see the Base Definitions volume of IEEE Std 1003.1-2001, Chapter 7, Locale.
Note: When the escape sequences of the list argument are used in a shell script, you must use single quotation marks; otherwise, the shell interprets the backslash character as a special character.

The input files must be text files.

-s
Concatenate all lines of each separate input file in command line order. Except for the last line in each input file, the <newline> of every line is replaced with <tab>, unless otherwise specified by the -d option.
file
The pathname of an input file. Specifying “-” for one or more of the files uses the standard input, which is input read one line at a time for each instance of “-”.

Description:

For every file you name, the paste utility pastes columns or fields from each line, concatenates them, and writes them to the standard output.

By default, paste assumes the field delimiter character to be tab. You can use the -d option to specify another delimiter.

Examples:

Write out a directory in three columns:

ls | paste - - -

Combine pairs of lines from a file into single lines:

paste -s -d "\t\n" file

Exit status:

0
Successful completion.
>0
An error occurred.