$linuxjunkies
>

paste(1)

Merge lines of files side-by-side, combining corresponding lines with a delimiter.

UbuntuDebianFedoraArch

Synopsis

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

Description

The paste command concatenates lines from multiple files horizontally (side-by-side) rather than vertically. By default, it joins corresponding lines from each file with a tab character, creating columnar output useful for combining related data.

If no files are specified, or if - is given as a filename, paste reads from standard input. This allows piping data directly into the command.

Common options

FlagWhat it does
-d DELIMUse DELIM as the field separator instead of tab; can specify multiple delimiters to cycle through
-sPaste one file at a time (serial mode) instead of merging across files
-zUse NUL character as line terminator instead of newline

Examples

Combine corresponding lines from two files side-by-side, separated by tabs

paste file1.txt file2.txt

Join three files with comma as the delimiter between columns

paste -d ',' file1.txt file2.txt file3.txt

Merge names and ages, separating columns with a colon

paste -d ':' names.txt ages.txt

Read from stdin and merge each line with itself (creates pairs of words)

cat data.txt | paste -d ' ' - -

Join all lines of a file into a single output (no actual side-by-side effect here)

paste -s -d '\n' list.txt

Alternate delimiters: tab, pipe, tab between columns

paste -d '\t|\t' first.txt last.txt

Convert newline-separated list of filenames into comma-separated values

ls *.txt | paste -sd ',' -

Related commands