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
| Command | Description |
|---|---|
paste file1 file2 | Merge two files line by line using default tab delimiter |
paste file1 file2 file3 | Merge multiple files side by side |
paste -d "," file1 file2 | Use comma as delimiter instead of tab |
paste -d ":" file1 file2 | Use colon as delimiter |
paste -d " " file1 file2 | Use space as delimiter |
paste -d "\t" file1 file2 | Explicitly use tab as delimiter |
paste -d ",;" file1 file2 | Use multiple delimiters in sequence |
paste -s file1 | Convert multiple lines into a single line (serialization) |
paste -s -d "," file1 | Convert lines to single line with comma separator |
paste -s file1 file2 | Serialize each file separately |
paste - - < file1 | Merge every two lines into one line |
paste - - - < file1 | Merge every three lines into one line |
paste <(cmd1) <(cmd2) | Merge outputs of two commands (process substitution) |
paste file1 file2 > output.txt | Save merged output to a file |
paste file1 file2 | column -t | Format output into aligned columns |
paste file1 file2 | sort | Merge and sort output |
paste file1 file2 | grep "pattern" | Merge and filter output |
paste --help | Display help for paste command |
paste --version | Show 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):
paste file1 file2Example (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
| Operation | Description |
|---|---|
| Copy-Paste (Ctrl+C / Ctrl+V) | Works with clipboard, inserts text into terminal |
| paste command | Combines 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
paste file1 file2This merges corresponding lines from both files using tab as default delimiter.
Example output:
A1 B1
A2 B2Convert Lines to Single Line (CSV Format)
paste -s -d "," file1This converts multiple lines into a single comma-separated line.
Example:
input:
A
B
C
output:
A,B,CUse Custom Delimiter (Comma, Space, etc.)
paste -d "," file1 file2Use comma instead of tab.
paste -d " " file1 file2Use space as delimiter.
paste -d ":" file1 file2Use colon as delimiter.
Real-World Use Cases
Combine Logs from Multiple Files
paste app.log db.logUseful for correlating logs from different sources line by line.
Create CSV from Text Files
paste -d "," names.txt marks.txt > output.csvCombine two files into CSV format for reporting or analysis.
Merge Command Outputs (Without Temp Files)
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.
paste -d ",;" file1 file2This will use , for the first column and ; for the next, then repeat.
Example:
input:
file1: A B C
file2: 1 2 3
output:
A,1
B;2
C,3Handle Unequal Line Counts
When files have different numbers of lines, paste continues with the remaining lines of the longer file.
paste file1 file2Example:
file1:
A
B
C
file2:
1
2
output:
A 1
B 2
CNo delimiter is added where data is missing.
Process Substitution with paste
You can combine outputs of commands without creating temporary files using process substitution.
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:
paste -d "," file1 file2Unexpected Output Formatting
If output looks misaligned, it is usually due to tabs.
Use column for better formatting:
paste file1 file2 | column -tFile Length Mismatch Issues
When files have unequal lines, output may appear incomplete.
To verify:
wc -l file1 file2Ensure 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:






![Create users in bulk using shell script [SOLVED]](/create-users-in-bulk-using-shell-script/create-users-in-bulk_hu_f4f465b33f33bbad.webp)



