paste — Merge Lines Horizontally

Merge lines side by side — the horizontal counterpart to cat for combining columnar data from multiple sources.

Merge Files Column-Wise

Paste two files side by side — tab-delimited by default
paste names.txt scores.txt
Paste three files — each becomes a column
paste first.txt last.txt email.txt
Paste with a specific delimiter — comma-separated
paste -d',' names.txt scores.txt
Paste with colon delimiter — build /etc/passwd-style records
paste -d':' users.txt uids.txt shells.txt

Serial Mode — -s

Transpose a file — all lines become one line, tab-separated
paste -s names.txt
Transpose with comma delimiter — create a comma-separated list
paste -sd',' names.txt
Transpose multiple files — each file becomes one row
paste -s file1.txt file2.txt file3.txt
Join lines of a single file with a space — flatten to one line
paste -sd' ' input.txt

Custom Delimiters — -d

Rotating delimiter — alternates through characters in the delimiter string
# paste cycles through the delimiter characters:
paste -d',;:' f1.txt f2.txt f3.txt f4.txt
# Between f1-f2: comma, f2-f3: semicolon, f3-f4: colon
Pair lines with comma, then separate pairs with newline — every two lines joined
paste -d',\n' - - < data.txt
Group every 3 lines into one tab-delimited record
paste - - - < data.txt
Group every 4 lines with comma delimiter
paste -d',' - - - - < data.txt

Process Substitution — paste with Commands

Combine command output as columns without temp files
paste <(cut -d':' -f1 /etc/passwd) <(cut -d':' -f7 /etc/passwd)
Side-by-side comparison of two command outputs
paste <(df -h | awk '{print $1, $5}') <(df -h | awk '{print $6}')
Number lines — paste line numbers alongside content
paste <(seq $(wc -l < data.txt)) data.txt
Merge sorted and original — see what sort changed
paste <(cat data.txt) <(sort data.txt) | column -t -s$'\t'
Build a lookup table from two commands
paste <(getent passwd | cut -d: -f3) <(getent passwd | cut -d: -f1) | sort -n

Building Tables from Parallel Streams

Create a CSV from parallel arrays
paste -d',' <(printf '%s\n' host1 host2 host3) <(printf '%s\n' 192.168.1.10 192.168.1.11 192.168.1.12) <(printf '%s\n' up up down)
Add headers to pasted output
(echo -e "NAME\tSCORE\tGRADE"; paste names.txt scores.txt grades.txt) | column -t
Interleave a file with a separator — insert blank lines between records
paste -d'\n' data.txt /dev/null | head -20

Practical Patterns

Reshape single-column data into N columns — e.g., 3 columns from one list
paste - - - < long_list.txt
Create key=value pairs from alternating lines
paste -d'=' - - < alternating.txt
# Input:     Output:
# name       name=alice
# alice      age=30
# age
# 30
Combine paste with column for aligned output
paste <(lsblk -dno NAME) <(lsblk -dno SIZE) <(lsblk -dno TYPE) | column -t
Quick side-by-side diff alternative — compare two files visually
paste <(awk '{printf "%-40s", $0}' file1.txt) file2.txt