Skip to content

paste Command Cheat Sheet

The paste command merges lines of files. While cat merges vertically (appends), paste merges horizontally.


Synopsis

paste [OPTION]... [FILE]...

Basic Usage

Merge Two Files

file1:

Alice
Bob
file2:
100
200

paste file1 file2
Output:
Alice   100
Bob 200
(Default separator is TAB).


Delimiters (-d)

Use Comma (CSV style)

paste -d "," file1 file2
# Output:
# Alice,100
# Bob,200

Multiple Delimiters

If you merge 3 files, paste cycles through delimiters.

paste -d ",|" file1 file2 file3
# Output:
# Alice,100|Engineer

Serial Mode (-s)

Merge lines from the same file into a single line.

paste -s file1
# Output:
# Alice Bob

Serial with Delimiter

Convert a newline-separated list into a comma-separated list.

paste -sd "," file1
# Output:
# Alice,Bob

Handling Stdin (-)

Read from standard input.

ls | paste - - -
This formats ls output into 3 columns! (The - represents Stdin. Three - means "read 3 lines from stdin and put them on one line").


Notes

  • vs join: join merges based on a common key (like SQL). paste just glues line 1 to line 1, regardless of content.
  • Useful for creating CSVs from separate data columns.