Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


Unix paste command

News Shells Recommended Links Options Examples Pipes AWK xargs
Environment find grep sort cut tee Exit Status Etc

The Unix paste command combines files horizontally. For simple cases it is Ok. for complex cases you need to use Perl or AWK instead.

The paste command is primarily used to paste files together horizontally. That is, each file is placed in a column on the output. It may also be used to take multiple files for input and generate one long serial line of output. A serial line of output has no new-line characters. Thus it is one long line. Another use is to take a stream of input and generate multiple columns of output.

If you have two files, it would display the first file in the left column and the second file in the second column. The paste command has various functions; they include:

COMMAND FORMAT

Following is the general format of the paste command.

       paste [ -d[list] ]  [-]file_list
       paste -s [ -d[list ]  file_list

Options

The following list describes the options and their arguments that may be used to control how paste functions.

- The standard input. Causes paste to read one line from the standard input.
-dlist Delimiter. Allows you to define what character you want to use to separate columns of output. If you do not specify a list, the output columns are displayed immediately next to each other.
If -d is not specified, a tab character separates all columns.
The list is zero or more characters used for output delimiters, replacing the default tab character. The list must follow immediately after the -d option. If list consists of multiple characters, paste uses the first character to separate columns one and two, the second character between columns two and three, and so on. If the list is completely used and more columns exist, then the list is reused from the beginning. Thus it is a circular delimiter list.
The list may contain any of the following standard C escape sequences:
\n A newline
\t A tab
\\ A backslash; since a backslash is a special character you must escape it.
\0 No character at all. Same as -d without a list. But may be used in multi- character list. Does not actually place a character on the output.
You may have to quote the list to keep the shell from interpreting certain characters. For example, to pass a backslash to paste you would have to type -d"\\" or -d'\'.
-s Serial output. Allows you to combine all lines of each file into one line of output. The -d option may be used to change the output delimiter. The last character of output is always a new-line.

Arguments

The following describes the argument that may be passed to the paste command.

file_list One or more files read and displayed in the appropriate format.

DIAGNOSTICS AND BUGS

The following messages may be displayed if paste encounters a problem.

line too long An input line is too long. The longest possible input is 511 characters.
too many files Only 12 input files can be specified; you entered 13 or more. The -s option is restricted by this limit.

Examples

  1. Type paste first city and press Return. The two files are combined line-by-line with tabs separating the two. Your screen should look like the following display.
           cj> paste first city
           Name    City
           Someone Austin
           Anyone  Dallas
    
  2. Type paste -s -d: first city and press Return. This creates a single line of output. Your screen should resemble the following display:
           cj> paste -d: -s first second
           Name:Someone:Anyone:City:Austin:Dallas
    
  3. Type ls /bin | paste - - - - and press Return to list out the files in the /bin directory in 4-column output. Each - tells paste to read a line from standard input. Since there are four files to read from, four columns are created for output.
           cj> ls /bin | paste - - - -
           adb     ar   as   basename
           .
           .
           .
    

Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: September 15, 2008