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 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
33
34 The following options shall be supported:
35
36 -d list
37 Unless a backslash character appears in list, each character in
38 list is an element specifying a delimiter character. If a back‐
39 slash character appears in list, the backslash character and one
40 or more characters following it are an element specifying a
41 delimiter character as described below. These elements specify
42 one or more delimiters to use, instead of the default <tab>, to
43 replace the <newline> of the input lines. The elements in list
44 shall be used circularly; that is, when the list is exhausted
45 the first element from the list is reused. When the -s option is
46 specified:
47
48 * The last <newline> in a file shall not be modified.
49
50 * The delimiter shall be reset to the first element of list
51 after each file operand is processed.
52
53 When the -s option is not specified:
54
55 * The <newline>s in the file specified by the last file operand
56 shall not be modified.
57
58 * The delimiter shall be reset to the first element of list
59 each time a line is processed from each file.
60
61 If a backslash character appears in list, it and the character follow‐
62 ing it shall be used to represent the following delimiter characters:
63
64 \n
65 <newline>.
66
67 \t
68 <tab>.
69
70 \\
71 Backslash character.
72
73 \0
74 Empty string (not a null character). If '\0' is immediately fol‐
75 lowed by the character 'x', the character 'X', or any character
76 defined by the LC_CTYPE digit keyword (see the Base Definitions
77 volume of IEEE Std 1003.1-2001, Chapter 7, Locale), the results
78 are unspecified.
79
80
81 If any other characters follow the backslash, the results are unspeci‐
82 fied.
83
84 -s Concatenate all of the lines of each separate input file in com‐
85 mand line order. The <newline> of every line except the last
86 line in each input file shall be replaced with the <tab>, unless
87 otherwise specified by the -d option.
88
89
91 The following operand shall be supported:
92
93 file A pathname of an input file. If '-' is specified for one or more
94 of the files, the standard input shall be used; the standard
95 input shall be read one line at a time, circularly, for each
96 instance of '-' . Implementations shall support pasting of at
97 least 12 file operands.
98
99
101 The standard input shall be used only if one or more file operands is
102 '-' . See the INPUT FILES section.
103
105 The input files shall be text files, except that line lengths shall be
106 unlimited.
107
109 The following environment variables shall affect the execution of
110 paste:
111
112 LANG Provide a default value for the internationalization variables
113 that are unset or null. (See the Base Definitions volume of
114 IEEE Std 1003.1-2001, Section 8.2, Internationalization Vari‐
115 ables for the precedence of internationalization variables used
116 to determine the values of locale categories.)
117
118 LC_ALL If set to a non-empty string value, override the values of all
119 the other internationalization variables.
120
121 LC_CTYPE
122 Determine the locale for the interpretation of sequences of
123 bytes of text data as characters (for example, single-byte as
124 opposed to multi-byte characters in arguments and input files).
125
126 LC_MESSAGES
127 Determine the locale that should be used to affect the format
128 and contents of diagnostic messages written to standard error.
129
130 NLSPATH
131 Determine the location of message catalogs for the processing of
132 LC_MESSAGES .
133
134
136 Default.
137
139 Concatenated lines of input files shall be separated by the <tab> (or
140 other characters under the control of the -d option) and terminated by
141 a <newline>.
142
144 The standard error shall be used only for diagnostic messages.
145
147 None.
148
150 None.
151
153 The following exit values shall be returned:
154
155 0 Successful completion.
156
157 >0 An error occurred.
158
159
161 If one or more input files cannot be opened when the -s option is not
162 specified, a diagnostic message shall be written to standard error, but
163 no output is written to standard output. If the -s option is specified,
164 the paste utility shall provide the default behavior described in Util‐
165 ity Description Defaults .
166
167 The following sections are informative.
168
170 When the escape sequences of the list option-argument are used in a
171 shell script, they must be quoted; otherwise, the shell treats the '\'
172 as a special character.
173
174 Conforming applications should only use the specific backslash escaped
175 delimiters presented in this volume of IEEE Std 1003.1-2001. Historical
176 implementations treat '\x', where 'x' is not in this list, as 'x', but
177 future implementations are free to expand this list to recognize other
178 common escapes similar to those accepted by printf and other standard
179 utilities.
180
181 Most of the standard utilities work on text files. The cut utility can
182 be used to turn files with arbitrary line lengths into a set of text
183 files containing the same data. The paste utility can be used to create
184 (or recreate) files with arbitrary line lengths. For example, if file
185 contains long lines:
186
187
188 cut -b 1-500 -n file > file1
189 cut -b 501- -n file > file2
190
191 creates file1 (a text file) with lines no longer than 500 bytes (plus
192 the <newline>) and file2 that contains the remainder of the data from
193 file. Note that file2 is not a text file if there are lines in file
194 that are longer than 500 + {LINE_MAX} bytes. The original file can be
195 recreated from file1 and file2 using the command:
196
197
198 paste -d "\0" file1 file2 > file
199
200 The commands:
201
202
203 paste -d "\0" ...
204 paste -d "" ...
205
206 are not necessarily equivalent; the latter is not specified by this
207 volume of IEEE Std 1003.1-2001 and may result in an error. The con‐
208 struct '\0' is used to mean "no separator" because historical versions
209 of paste did not follow the syntax guidelines, and the command:
210
211
212 paste -d"" ...
213
214 could not be handled properly by getopt().
215
217 1. Write out a directory in four columns:
218
219
220 ls | paste - - - -
221
222 2. Combine pairs of lines from a file into single lines:
223
224
225 paste -s -d "\t\n" file
226
228 None.
229
231 None.
232
234 Utility Description Defaults, cut, grep, pr
235
237 Portions of this text are reprinted and reproduced in electronic form
238 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
239 -- Portable Operating System Interface (POSIX), The Open Group Base
240 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
241 Electrical and Electronics Engineers, Inc and The Open Group. In the
242 event of any discrepancy between this version and the original IEEE and
243 The Open Group Standard, the original IEEE and The Open Group Standard
244 is the referee document. The original Standard can be obtained online
245 at http://www.opengroup.org/unix/online.html .
246
247
248
249IEEE/The Open Group 2003 PASTE(1P)