paste(1) paste(1)
NAME
paste - merge same lines of several files or subsequent lines of one
file
SYNOPSIS
paste [-d list] [--] file ... Format 1
paste -s [-d list] [--] file ... Format 2
DESCRIPTION
paste can be used to horizontally merge the n-th corresponding lines
from two or more input files (parallel merging, Format 1) or to suc-
cessively merge all lines within a single file (serial merging, Format
2). The result is written to standard output.
OPTIONS
Format 1: Joining the n-th lines of several files (parallel merging)
paste [-d list] [--] file ...
paste concatenates the n-th line of each input file, treating each
file as a column or columns of a table. The corresponding lines are
pasted together horizontally and displayed on the standard output (see
Example 1).
No option specified:
The tab character acts as a delimiter between columns.
-d list
(d - delimiter) Uses a character from list as a delimiter between
output columns.
The characters in list are used consecutively and circularly,
i.e. paste returns to the top of the list after using the last
character in it. In parallel merging, lines from the last input
file are always terminated with a newline character, not with a
character from the list.
Any string of arbitrary characters can be specified for list. The
following escape sequences may also be used: \n (newline), \t
(tab), \\ (backslash), and \0 (empty string, not a null charac-
ter). If list contains escape sequences, blanks, or shell meta-
characters, it must be enclosed in double quotes "...".
-- If file begins with a dash (-), the end of the command-line
options must be marked with --.
file Name of the input file. This format of paste is only meaningful
if you specify several files.
If you use a dash (-) as the name for file, paste reads from
standard input.
Page 1 Reliant UNIX 5.44 Printed 11/98
paste(1) paste(1)
Format 2: Joining successive lines (serial merging)
paste -s [-d list] [--] file ...
-s (s - subsequent) For each input file, paste joins the lines
together to form a single line and writes this line to standard
output. By default, the lines from the input file are separated
by tabs (see option d). Each output line is terminated by a new-
line character.
-d list
(d - delimiter) One of the characters from list is used in the
output line instead of a tab to mark the joins between the input
lines.
The characters in list are used consecutively and circularly,
i.e. paste returns to the top of the list after using the last
character in it.
Any string of arbitrary characters can be specified for list. The
following escape sequences may also be used: \n (newline), \t
(tab), \\ (backslash), and \0 (empty string, not a null charac-
ter). If list contains escape sequences, blanks, or shell meta-
characters, it must be enclosed in double quotes "...".
-- If file begins with a dash (-), the end of the command-line
options must be marked with --.
file Name of the input file. You may name more than one file.
If you use a dash (-) as the name for file, paste reads from
standard input.
ERROR MESSAGES
paste: line too long
Output lines must not exceed 511 characters.
paste: too many files - limit 12
A maximum of 12 input files may be specified in Format 1.
paste: no delimiters
You have not specified list with the -d option.
paste: cannot open file
file does not exist or you do not have read permission for file.
Page 2 Reliant UNIX 5.44 Printed 11/98
paste(1) paste(1)
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed. If LCMESSAGES is undefined or is defined
as the null string, it defaults to the value of LANG. If LANG is like-
wise undefined or null, the system acts as if it were not internation-
alized.
The LCALL environment variable governs the entire locale. LCALL
takes precedence over all the other environment variables which affect
internationalization.
EXAMPLES
Examples of Format 1
Example 1
The corresponding lines from the files numbers and letters are to be
pasted together:
The numbers file contains numbers from 1 to 100:
1
2
3
.
.
100
The letters file contains lowercase letters from a to z:
a
b
c
.
.
z
$ paste numbers letters
1 a
2 b
3 c
. .
. .
25 y
26 z
27
.
.
100
Page 3 Reliant UNIX 5.44 Printed 11/98
paste(1) paste(1)
Example 2
The current directory contains the following files:
$ ls
corr
jokes
names
plan
probe
prog.c
tst
words
The following command numbers these files (see the numbers file in
Example 1):
$ ls | paste numbers -
1 corr
2 jokes
3 names
4 plan
5 probe
6 prog.c
7 tst
8 words
9
10
.
.
100
See also Example 3.
Example 3
The current directory contains the same files as in Example 2. The
following command lists the contents of the current directory in three
columns. However, the columns will only be justified properly if the
individual file names do not extend beyond the next tab stop.
$ ls | paste - - -
corr jokes names
plan probe prog.c
tst words
How is this output produced? Compare the above command with the com-
mand
$ paste file1 file2 file3
Page 4 Reliant UNIX 5.44 Printed 11/98
paste(1) paste(1)
In this case, paste first reads the initial lines from all three files
and pastes them into one line. When this is done, the second lines are
read, etc.
In the command ls | paste - - -, the first file name that paste reads
from standard input (corr) corresponds to the first line from file1;
the second file name jokes corresponds to the first line from file2
etc.
Example 4
The current directory contains the same files as in Example 2. As in
Example 3, you now wish to display the file names in three columns,
but the second and third columns are to be separated by a colon
instead of a tab.
$ ls | paste -d "\t:" - - -
corr jokes:names
plan probe:prog.c
tst words:
Example of Format 2
Example 5
The customers file contains the following:
hansen
smith
cologne
koch
schulz
london
tornio
meyer
perth
$ paste -s customers
hansen smith cologne koch schulz london tornio meyer perth
The following command joins only three lines of the customers file at
a time. This is because a newline character is specified as a delim-
iter after every third input line:
$ paste -s -d "\t\t\n" customers
hansen smith cologne
koch schulz london
tornio meyer perth
SEE ALSO
cut(1), grep(1), pr(1).
Page 5 Reliant UNIX 5.44 Printed 11/98