Paste Command in Linux: Examples, Use Cases & Cheat Sheet (2026 Guide)

Paste Command in Linux: Examples, Use Cases & Cheat Sheet (2026 Guide)

The paste command in Linux is used to merge lines of files horizontally, making it useful for combining data side by side. It is commonly used in text processing, scripting, and creating structured outputs like CSV files. With support for custom delimiters and serialization, paste becomes a powerful tool for everyday command-line operations.


Paste Command - Quick Cheat Sheet

CommandDescription
paste file1 file2Merge two files line by line using default tab delimiter
paste file1 file2 file3Merge multiple files side by side
paste -d "," file1 file2Use comma as delimiter instead of tab
paste -d ":" file1 file2Use colon as delimiter
paste -d " " file1 file2Use space as delimiter
paste -d "\t" file1 file2Explicitly use tab as delimiter
paste -d ",;" file1 file2Use multiple delimiters in sequence
paste -s file1Convert multiple lines into a single line (serialization)
paste -s -d "," file1Convert lines to single line with comma separator
paste -s file1 file2Serialize each file separately
paste - - < file1Merge every two lines into one line
paste - - - < file1Merge every three lines into one line
paste <(cmd1) <(cmd2)Merge outputs of two commands (process substitution)
paste file1 file2 > output.txtSave merged output to a file
paste file1 file2 | column -tFormat output into aligned columns
paste file1 file2 | sortMerge and sort output
paste file1 file2 | grep "pattern"Merge and filter output
paste --helpDisplay help for paste command
paste --versionShow version information

How to Paste in Linux

paste Command vs Ctrl+V

In Linux, there are two different meanings of "paste":

  • paste command → merges lines from files horizontally
  • Ctrl+V / Ctrl+Shift+V → inserts clipboard content into terminal

Example (paste command):

text
paste file1 file2

Example (terminal paste):

  • Ctrl + Shift + V (most terminals)
  • Middle mouse click (X11 systems)

Use paste command when working with files and structured data, not for clipboard operations.

Copy-Paste vs paste Command

OperationDescription
Copy-Paste (Ctrl+C / Ctrl+V)Works with clipboard, inserts text into terminal
paste commandCombines file contents line-by-line

If you want to merge files → use paste
If you want to insert copied text → use keyboard shortcuts


Most Common paste Command Examples

Merge Two Files Side by Side

text
paste file1 file2

This merges corresponding lines from both files using tab as default delimiter.

Example output:

text
A1    B1
A2    B2

Convert Lines to Single Line (CSV Format)

text
paste -s -d "," file1

This converts multiple lines into a single comma-separated line.

Example:

text
input:
A
B
C

output:
A,B,C

Use Custom Delimiter (Comma, Space, etc.)

text
paste -d "," file1 file2

Use comma instead of tab.

text
paste -d " " file1 file2

Use space as delimiter.

text
paste -d ":" file1 file2

Use colon as delimiter.


Real-World Use Cases

Combine Logs from Multiple Files

text
paste app.log db.log

Useful for correlating logs from different sources line by line.

Create CSV from Text Files

text
paste -d "," names.txt marks.txt > output.csv

Combine two files into CSV format for reporting or analysis.

Merge Command Outputs (Without Temp Files)

text
paste <(cut -f1 file1) <(cut -f2 file2)

Combine outputs of commands directly without creating intermediate files.


Advanced paste Command Usage

Use Multiple Delimiters (-d)

The -d option allows you to use multiple delimiters in sequence. These delimiters are applied cyclically.

text
paste -d ",;" file1 file2

This will use , for the first column and ; for the next, then repeat.

Example:

text
input:
file1: A B C
file2: 1 2 3

output:
A,1
B;2
C,3

Handle Unequal Line Counts

When files have different numbers of lines, paste continues with the remaining lines of the longer file.

text
paste file1 file2

Example:

text
file1:
A
B
C

file2:
1
2

output:
A    1
B    2
C

No delimiter is added where data is missing.

Process Substitution with paste

You can combine outputs of commands without creating temporary files using process substitution.

text
paste <(cut -f1 file1) <(cut -f2 file2)

This is useful for dynamically generating inputs.


Common Errors and Fixes

Why Output is Tab-Separated

By default, paste uses a tab (\t) as the delimiter.

To change it, use:

text
paste -d "," file1 file2

Unexpected Output Formatting

If output looks misaligned, it is usually due to tabs.

Use column for better formatting:

text
paste file1 file2 | column -t

File Length Mismatch Issues

When files have unequal lines, output may appear incomplete.

To verify:

text
wc -l file1 file2

Ensure both files have equal lines if strict pairing is required.


Frequently Asked Questions

1. What is paste command in Linux?

The paste command in Linux is used to merge lines from one or more files horizontally, using tab or custom delimiters.

2. How to use paste command in Linux?

You can use paste file1 file2 to merge two files side by side or paste -s file to combine lines into a single line.

3. What is the difference between paste and copy-paste in Linux?

The paste command merges file contents, while copy-paste (Ctrl+V) inserts clipboard content into the terminal.

4. How to change delimiter in paste command?

Use the -d option followed by a delimiter, for example paste -d "," file1 file2.

5. How to convert lines to a single line using paste?

Use paste -s file to serialize multiple lines into a single line output.

Summary

The paste command is a simple yet powerful utility for merging file contents horizontally. It supports custom delimiters, serialization, and integration with other Linux commands. Whether you're working with logs, CSV data, or command outputs, paste helps streamline text processing tasks efficiently.


Further Reading

Related Commands:

Deepak Prasad

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.