paste Command in Linux: Merge Lines, Delimiters & Practical Examples

paste merges corresponding lines from one or more files into wider rows — tab-separated by default, or with custom delimiters. Use it to build columns, CSV-style output, and one-line serializations in shell pipelines.

Published

Updated

Read time 7 min read

Reviewed byDeepak Prasad

paste Command in Linux: Merge Lines, Delimiters & Practical Examples
About paste merges corresponding lines from one or more files into wider rows — tab-separated by default, or with custom delimiters. Use it to build columns, CSV-style output, and one-line serializations in shell pipelines.
Tested on Ubuntu 25.04 (Plucky Puffin); paste (uutils coreutils) 0.2.2; kernel 7.0.0-27-generic
Package coreutils-from-uutils (apt/deb) · coreutils (dnf/rpm)
Man page paste(1)
Privilege none
Distros

GNU coreutils and uutils coreutils (Ubuntu 25.04 ships uutils paste).

Clipboard paste (Ctrl+Shift+V) is unrelated — this page covers the paste command only.

Related guide

paste — quick reference

Merge files in parallel

Combine line 1 from file A with line 1 from file B, and so on — like adding columns.

When to use Command
Merge two files side by side (tab between columns) paste file1 file2
Merge three or more files on one line each paste file1 file2 file3
Read from stdin when a filename is - paste file1 -
Save merged output to a new file paste file1 file2 > merged.txt

Custom delimiters

Replace the default tab with commas, colons, or a repeating delimiter list.

When to use Command
Comma-separated output paste -d ',' file1 file2
Colon-separated output paste -d ':' file1 file2
Space-separated output paste -d ' ' file1 file2
Cycle through multiple delimiters (, then ;, repeat) paste -d ',;' file1 file2

Serialize lines

Turn many lines in one file into a single row — common for CSV headers or argument lists.

When to use Command
Join all lines of one file with tabs paste -s file1
Join all lines with commas paste -s -d ',' file1
Serialize each file separately (not in parallel) paste -s file1 file2

Stdin tricks

Pair lines from one stream without splitting into temp files.

When to use Command
Merge every two lines from stdin into one row paste - - < file1
Merge every three lines into one row paste - - - < file1
Merge outputs of two commands (process substitution) paste <(cmd1) <(cmd2)

Output formatting

When to use Command
Align tab columns for reading paste file1 file2 | column -t
NUL-terminated lines instead of newlines paste -z file1 file2

Help and version

When to use Command
Show built-in usage paste --help
Show package version paste --version

paste — command syntax

Synopsis from paste --help on Ubuntu 25.04 (uutils paste 0.2.2):

text
paste [OPTIONS] [FILE]...

With no FILE arguments, paste reads stdin. Default field separator is a tab. paste does not change source files — output goes to stdout unless you redirect it.


paste — command examples

Essential Merge two files line by line

Combine two parallel lists into columns — for example names in one file and scores in another.

Create sample files and merge them:

bash
printf 'A1\nA2\nA3\n' > /tmp/f1.txt
printf 'B1\nB2\n' > /tmp/f2.txt
paste /tmp/f1.txt /tmp/f2.txt

Sample output:

output
A1	B1
A2	B2
A3

The third row has only A3 because f2.txt ran out of lines — paste does not pad missing fields.

Essential Serialize many lines into one row

Use -s when you need one line of tab- or comma-separated values from a multi-line file.

Run the command:

bash
printf 'A1\nA2\nA3\n' > /tmp/f1.txt
paste -s /tmp/f1.txt

Sample output:

output
A1	A2	A3

Add -d ',' when downstream tools expect CSV-style commas instead of tabs.

Essential Unequal line counts — no padding

When files differ in length, paste keeps going with whatever lines remain in the longer file.

Run the command:

bash
paste /tmp/f1.txt /tmp/f2.txt
wc -l /tmp/f1.txt /tmp/f2.txt

Sample output:

output
A1	B1
A2	B2
A3	
  3 /tmp/f1.txt
  2 /tmp/f2.txt
  5 total

Use wc -l first when strict pairing matters — trim or pad files before merging if every row must have the same number of columns.

Common Comma delimiter for CSV-style output

Replace tabs with commas when feeding spreadsheets or tools that expect CSV.

Run the command:

bash
paste -d ',' /tmp/f1.txt /tmp/f2.txt

Sample output:

output
A1,B1
A2,B2
A3,

The trailing comma on A3, marks an empty second column where f2.txt had no third line.

Common Pair lines from one file (paste - -)

Merge every two consecutive lines without creating intermediate files — useful for key/value pairs stored on alternating lines.

Run the command:

bash
paste - - < /tmp/f1.txt

Sample output:

output
A1	A2
A3

Each - is one copy of stdin; paste reads two lines per output row. Use three - arguments to group triples.

Common Build a small CSV from two text columns

A typical reporting pattern: headers plus data rows from parallel extracts.

Run the command:

bash
printf 'name\nalice\nbob\n' > /tmp/names.txt
printf '90\n85\n' > /tmp/marks.txt
paste -d ',' /tmp/names.txt /tmp/marks.txt

Sample output:

output
name,90
alice,85
bob,

Redirect to a .csv file when the output is final: paste -d ',' names.txt marks.txt > report.csv.

Advanced Cycle delimiters with -d ',;'

Multiple characters in -d are reused in order — handy when columns need different separators.

Run the command:

bash
paste -d ',;' /tmp/f1.txt /tmp/f2.txt

Sample output:

output
A1,B1
A2;B2
A3,

With two files, the first delimiter separates columns on row 1, the second on row 2, then the pattern repeats. The lone A3, shows the third row still uses , but f2.txt had no third line.

Advanced Merge command outputs without temp files

Process substitution feeds two command streams into paste in one pipeline.

Run the command:

bash
paste <(cut -d ':' -f 1 /etc/passwd | head -3) <(cut -d ':' -f 3 /etc/passwd | head -3)

Sample output:

output
root	0
daemon	1
bin	2

First column is usernames; second is UID fields from the same lines of /etc/passwd. See the cut command for field selection details.


paste — when to use / when not

Use paste when Use something else when
  • Two or more files have the same line order and you want wider rows
  • You need tab- or comma-separated columns without a full database join
  • You want to collapse many lines into one serialized row (`-s`)
  • You are building quick shell pipelines from command output
  • Rows must match on a key column that is not line-aligned → awk
  • You need to extract one column from each line → cut
  • You are inserting clipboard text in a terminal → keyboard paste (Ctrl+Shift+V), not the paste command
  • Fields are separated by variable spaces → awk with whitespace rules

paste vs cut

paste cut
Direction Adds columns (merges files horizontally) Removes columns (keeps selected fields)
Input Two or more streams with aligned line numbers One stream per invocation
Default separator Tab between merged columns Tab between fields

They are often chained: cut to pull fields, paste to recombine them.


Command One line
paste Merge lines horizontally (this page)
sort Sort rows before or after merging

Browse the full index in our Linux commands reference.


paste — interview corner

What does the paste command do in Linux?

paste reads lines from one or more files and writes one output line per index — line 1 from each file merged, then line 2, and so on. The default delimiter between merged fields is a tab.

bash
paste file1 file2

It is a file-merge tool, not clipboard paste.

A strong answer is:

"paste merges corresponding lines from multiple files into wider rows, tab-separated by default. I use it for side-by-side columns and quick CSV builds."

Is paste the same as Ctrl+V in the terminal?

No. Terminal paste inserts text from the clipboard into your shell or editor. The paste command combines file contents on stdout.

Action Tool
Clipboard → terminal Ctrl+Shift+V (most terminals)
file1 + file2 → wider rows paste file1 file2

A strong answer is:

"Different things — paste the command merges files; clipboard paste is a terminal shortcut."

How do you turn a multi-line file into one line?

Use serialize mode -s:

bash
paste -s -d ',' file

That prints all lines on a single row, separated by commas (or whatever -d specifies).

A strong answer is:

"paste -s serializes lines into one row; -d picks the separator, often comma for CSV-style output."

What happens when input files have different line counts?

paste does not stop or pad — it emits rows until all files are exhausted. The shorter file simply contributes nothing for later lines.

Check lengths with wc -l when you need strict pairing.

A strong answer is:

"The longer file keeps going; missing fields are empty. I verify with wc -l when alignment must be exact."

How do you change the delimiter in paste?

Pass -d with the character (or list of characters) to use instead of tab:

bash
paste -d ',' names marks

Multiple characters cycle: -d ',;' alternates comma and semicolon between columns on successive rows.

A strong answer is:

"-d sets the delimiter; a string of characters cycles per row. Default is tab."


Troubleshooting

Symptom Likely cause Fix
Columns look misaligned in the terminal Default tabs — terminal font/proportional spacing Pipe to column -t or use -d ',' for CSV
Trailing empty column One file has fewer lines Expected behaviour; pad the shorter file or trim the longer one
paste: invalid delimiter Empty or multi-byte delimiter on some builds Use a single ASCII character with -d
Merged rows do not match logically Line order differs between files Sort both files first or use awk for keyed joins
Garbled binary data NUL bytes in input Try paste -z for NUL-terminated records

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …