1PASTE(1P) POSIX Programmer's Manual PASTE(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 paste — merge corresponding or subsequent lines of files
13
15 paste [-s] [-d list] file...
16
18 The paste utility shall concatenate the corresponding lines of the
19 given input files, and write the resulting lines to standard output.
20
21 The default operation of paste shall concatenate the corresponding
22 lines of the input files. The <newline> of every line except the line
23 from the last input file shall be replaced with a <tab>.
24
25 If an end-of-file condition is detected on one or more input files, but
26 not all input files, paste shall behave as though empty lines were read
27 from the files on which end-of-file was detected, unless the -s option
28 is specified.
29
31 The paste utility shall conform to the Base Definitions volume of
32 POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
33
34 The following options shall be supported:
35
36 -d list Unless a <backslash> character appears in list, each charac‐
37 ter in list is an element specifying a delimiter character.
38 If a <backslash> character appears in list, the <backslash>
39 character and one or more characters following it are an ele‐
40 ment specifying a delimiter character as described below.
41 These elements specify one or more delimiters to use, instead
42 of the default <tab>, to replace the <newline> of the input
43 lines. The elements in list shall be used circularly; that
44 is, when the list is exhausted the first element from the
45 list is reused. When the -s option is specified:
46
47 * The last <newline> in a file shall not be modified.
48
49 * The delimiter shall be reset to the first element of list
50 after each file operand is processed.
51
52 When the -s option is not specified:
53
54 * The <newline> characters in the file specified by the
55 last file operand shall not be modified.
56
57 * The delimiter shall be reset to the first element of list
58 each time a line is processed from each file.
59
60 If a <backslash> character appears in list, it and the char‐
61 acter following it shall be used to represent the following
62 delimiter characters:
63
64 \n <newline>.
65
66 \t <tab>.
67
68 \\ <backslash> character.
69
70 \0 Empty string (not a null character). If '\0' is immedi‐
71 ately followed by the character 'x', the character 'X',
72 or any character defined by the LC_CTYPE digit keyword
73 (see the Base Definitions volume of POSIX.1‐2017, Chap‐
74 ter 7, Locale), the results are unspecified.
75
76 If any other characters follow the <backslash>, the results
77 are unspecified.
78
79 -s Concatenate all of the lines from each input file into one
80 line of output per file, in command line order. The <newline>
81 of every line except the last line in each input file shall
82 be replaced with a <tab>, unless otherwise specified by the
83 -d option. If an input file is empty, the output line corre‐
84 sponding to that file shall consist of only a <newline> char‐
85 acter.
86
88 The following operand shall be supported:
89
90 file A pathname of an input file. If '-' is specified for one or
91 more of the files, the standard input shall be used; the
92 standard input shall be read one line at a time, circularly,
93 for each instance of '-'. Implementations shall support
94 pasting of at least 12 file operands.
95
97 The standard input shall be used only if one or more file operands is
98 '-'. See the INPUT FILES section.
99
101 The input files shall be text files, except that line lengths shall be
102 unlimited.
103
105 The following environment variables shall affect the execution of
106 paste:
107
108 LANG Provide a default value for the internationalization vari‐
109 ables that are unset or null. (See the Base Definitions vol‐
110 ume of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
111 ables the precedence of internationalization variables used
112 to determine the values of locale categories.)
113
114 LC_ALL If set to a non-empty string value, override the values of
115 all the other internationalization variables.
116
117 LC_CTYPE Determine the locale for the interpretation of sequences of
118 bytes of text data as characters (for example, single-byte as
119 opposed to multi-byte characters in arguments and input
120 files).
121
122 LC_MESSAGES
123 Determine the locale that should be used to affect the format
124 and contents of diagnostic messages written to standard
125 error.
126
127 NLSPATH Determine the location of message catalogs for the processing
128 of LC_MESSAGES.
129
131 Default.
132
134 Concatenated lines of input files shall be separated by the <tab> (or
135 other characters under the control of the -d option) and terminated by
136 a <newline>.
137
139 The standard error shall be used only for diagnostic messages.
140
142 None.
143
145 None.
146
148 The following exit values shall be returned:
149
150 0 Successful completion.
151
152 >0 An error occurred.
153
155 If one or more input files cannot be opened when the -s option is not
156 specified, a diagnostic message shall be written to standard error, but
157 no output is written to standard output. If the -s option is specified,
158 the paste utility shall provide the default behavior described in Sec‐
159 tion 1.4, Utility Description Defaults.
160
161 The following sections are informative.
162
164 When the escape sequences of the list option-argument are used in a
165 shell script, they must be quoted; otherwise, the shell treats the
166 <backslash> as a special character.
167
168 Conforming applications should only use the specific <back‐
169 slash>-escaped delimiters presented in this volume of POSIX.1‐2017.
170 Historical implementations treat '\x', where 'x' is not in this list,
171 as 'x', but future implementations are free to expand this list to rec‐
172 ognize other common escapes similar to those accepted by printf and
173 other standard utilities.
174
175 Most of the standard utilities work on text files. The cut utility can
176 be used to turn files with arbitrary line lengths into a set of text
177 files containing the same data. The paste utility can be used to create
178 (or recreate) files with arbitrary line lengths. For example, if file
179 contains long lines:
180
181
182 cut -b 1-500 -n file > file1
183 cut -b 501- -n file > file2
184
185 creates file1 (a text file) with lines no longer than 500 bytes (plus
186 the <newline>) and file2 that contains the remainder of the data from
187 file. Note that file2 is not a text file if there are lines in file
188 that are longer than 500 + {LINE_MAX} bytes. The original file can be
189 recreated from file1 and file2 using the command:
190
191
192 paste -d "\0" file1 file2 > file
193
194 The commands:
195
196
197 paste -d "\0" ...
198 paste -d "" ...
199
200 are not necessarily equivalent; the latter is not specified by this
201 volume of POSIX.1‐2017 and may result in an error. The construct '\0'
202 is used to mean ``no separator'' because historical versions of paste
203 did not follow the syntax guidelines, and the command:
204
205
206 paste -d"" ...
207
208 could not be handled properly by getopt().
209
211 1. Write out a directory in four columns:
212
213
214 ls | paste - - - -
215
216 2. Combine pairs of lines from a file into single lines:
217
218
219 paste -s -d "\t\n" file
220
222 None.
223
225 None.
226
228 Section 1.4, Utility Description Defaults, cut, grep, pr
229
230 The Base Definitions volume of POSIX.1‐2017, Chapter 7, Locale, Chapter
231 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
232
234 Portions of this text are reprinted and reproduced in electronic form
235 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
236 table Operating System Interface (POSIX), The Open Group Base Specifi‐
237 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
238 Electrical and Electronics Engineers, Inc and The Open Group. In the
239 event of any discrepancy between this version and the original IEEE and
240 The Open Group Standard, the original IEEE and The Open Group Standard
241 is the referee document. The original Standard can be obtained online
242 at http://www.opengroup.org/unix/online.html .
243
244 Any typographical or formatting errors that appear in this page are
245 most likely to have been introduced during the conversion of the source
246 files to man page format. To report such errors, see https://www.ker‐
247 nel.org/doc/man-pages/reporting_bugs.html .
248
249
250
251IEEE/The Open Group 2017 PASTE(1P)