🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

paste Command

Intermediate Text Processing man(1)

Merge lines of files side by side

👁 9 views 📅 Updated: Mar 15, 2026
SYNTAX
paste [OPTION]... [FILE]...

What Does paste Do?

The paste command merges lines from multiple files side by side, combining corresponding lines with a delimiter (tab by default). It is the complement to cut — while cut extracts columns, paste joins them.

paste can also serialize a file by converting its lines into columns, effectively transposing rows. This is useful for transforming line-based data into tabular format or creating comma-separated values from a list.

The command is particularly useful for combining data from parallel processing, merging columns from different sources, and reformatting data for import into spreadsheets or databases.

Options & Flags

OptionDescriptionExample
-d Set delimiter(s) between merged fields paste -d',' file1.txt file2.txt
-s Serialize — paste lines of each file in sequence paste -s -d, names.txt
-z Use null character as line delimiter paste -z file1 file2
- Read from stdin (use - for each column) seq 6 | paste - - -
-d list Cycle through multiple delimiters paste -d',;' file1 file2 file3
multiple files Merge corresponding lines from N files paste names.txt emails.txt phones.txt

Practical Examples

#1 Merge two files side by side

Combines corresponding lines from both files, separated by tab.
$ paste names.txt scores.txt
Output: Alice 95 Bob 87

#2 Use comma as delimiter

Creates CSV-like output from three separate files.
$ paste -d',' first.txt last.txt email.txt
Output: John,Doe,john@example.com

#3 Convert list to single line

Serializes all lines into one comma-separated line.
$ paste -sd, names.txt
Output: Alice,Bob,Charlie,Dave

#4 Create columns from stream

Groups sequential numbers into 3 columns using stdin placeholders.
$ seq 9 | paste - - -
Output: 1 2 3 4 5 6 7 8 9

#5 Merge with numbered lines

Combines line numbers with file content.
$ seq 5 | paste -d': ' - - < names.txt

#6 Create tab-separated from two commands

Combines usernames and shells using process substitution.
$ paste <(cut -d: -f1 /etc/passwd) <(cut -d: -f7 /etc/passwd)
Output: root /bin/bash www-data /usr/sbin/nologin

Tips & Best Practices

Transpose rows to columns: Use paste -s to convert a column of data into a single row. This is useful for creating comma-separated lists: paste -sd, file.txt
paste vs join: paste merges by line position (line 1 with line 1). join merges by matching key values (like SQL JOIN). Use join when files share a common key column.
Uneven files: If files have different numbers of lines, paste uses empty strings for the shorter file. This can create trailing delimiters.

Frequently Asked Questions

How do I combine two files side by side?
Use paste file1.txt file2.txt. By default, columns are separated by tab. Use -d',' for comma separation.
How do I convert a column to a comma-separated row?
Use paste -sd, file.txt. The -s flag serializes (merges all lines) and -d, sets comma as the delimiter.
What is the difference between paste and pr?
paste merges files by combining corresponding lines. pr formats files for printing with headers, columns, and pagination. For column merging, use paste.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →