Text and processing

The paste command

Pastes lines from several files side by side, or joins one file's lines into one.

Syntax

paste [-d lista] [-s] archivo...Try it in the terminal →

Most useful options

-d, --delimiters LISTASeparators used between columns, instead of the tab. Backslash escapes such as \t are accepted
-s, --serialPastes one file after another instead of in parallel: each file ends up on a single line
-z, --zero-terminatedUses the NUL byte as the line terminator instead of the newline
-Reads standard input at that position in the list of files

Copy-ready examples

$ printf 'a\nb\n' > p1.txt && printf '1\n2\n' > p2.txt && paste p1.txt p2.txtpastes two files line by line, with a tab between columns.

Example output

a	1
b	2
$ paste -d ',' p1.txt p2.txtthe same with a comma as separator, easier to read.

Example output

a,1
b,2
$ paste -s -d ',' p2.txtjoins all the lines of one file into a single line, separated by commas.

Example output

1,2
$ printf '1\n2\n3\n4\n' | paste - -groups the input lines two at a time.

Example output

1	2
3	4

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
paste: nonexist: No such file or directoryOne of the files does not exist or the name is misspelled.Check the name with ls and run paste again.
paste: carpeta: Is a directoryYou passed a folder. paste only reads files and standard input.Give a specific file inside the folder.

Typical mistakes

  • The default separator is a tab, which is hard to see on screen. With -d ',' the output is easier to read.
  • paste joins by position, not by content: if the lines are not in the same order, the columns end up mismatched. To join by key, use join.
  • The -d list is reused: with three files and -d ',;' the first gap uses a comma and the second a semicolon, in that order.

Differences from similar commands

  • cut: extracts columns from each line. paste does the opposite: it glues lines from several files together.
  • join: joins on the value of a key field. paste glues by line position without looking at the content.
  • column: aligns text you already have into columns. paste joins files line by line.

Related commands

FAQ

What if the files have a different number of lines?

It pads with empty up to the longest. The gap shows up as a tab followed by nothing.

How do I turn all the lines of a file into one?

With paste -s file: it joins all the lines with tabs. With -s -d ',' you separate them by commas, in one step.

Can it read from a pipe?

Yes: with - instead of a file it reads standard input. paste - - groups the lines two at a time.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course