Pasting sections of text files (paste command)

Use the paste command to merge the lines of up to 12 files into one file.

See the following examples:
  • If you have a file named names that contains the following text:
    rachel
    jerry
    mark
    linda
    scott
    and another file named places that contains the following text:
    New York
    Austin
    Chicago
    Boca Raton
    Seattle
    and another file named dates that contains the following text:
    February 5
    March 13
    June 21
    July 16
    November 4
    To paste the text of the files names, places, and dates together, type the following:
    paste names places dates > npd
    This creates a file named npd that contains the data from the names file in one column, the places file in another, and the dates file in a third. The npd file now contains the following:
    rachel          New York        February 5
    jerry           Austin          March 13
    mark            Chicago         June 21
    linda           Boca Raton      July 16
    scott           Seattle         November 4
    A tab character separates the name, place, and date on each line. These columns do not align, because the tab stops are set at every eighth column.
  • To separate the columns with a character other than a tab, type the following:
    paste -d"!@" names places dates > npd
    This alternates ! and @ as the column separators. If the names, places, and dates files are the same as in example 1, then the npd file contains the following:
    rachel!New York@February 5
    jerry!Austin@March 13
    mark!Chicago@June 21
    linda!Boca Raton@July 16
    scott!Seattle@November 4
  • To list the current directory in four columns, type the following:
    ls | paste - - - -
    Each hyphen (-) tells the paste command to create a column containing data read from the standard input. The first line is put in the first column, the second line in the second column, and so on.