Linux paste Command: Join Corresponding Lines Side by Side

paste takes corresponding lines from multiple files and joins them side by side into a single line. The default delimiter is a tab, and it can also be used to turn vertically stacked values into a single line.

What is the paste command?

Unlike cat, which concatenates file contents vertically, paste matches the first lines together, the second lines together, and so on. If the file lengths differ, the shorter one is filled with empty fields.

Basic syntax

paste [option] [file...]

Installed implementations and options may vary depending on the distribution. Check the description on the current system with man paste.

Examples

Combine two files by columns

Attach the corresponding line from the second file next to each line of the first file.

paste names.txt scores.txt

Specify a delimiter

Use a colon instead of a tab to separate values from the two files.

paste -d ':' names.txt scores.txt

Changing one file into one row

-s reads the file continuously and joins the lines horizontally.

paste -s -d ',' names.txt

Combine lines of two inputs

This command places the first lines of two files side by side, and the second lines side by side, and so on. The example below does not create actual files because it uses process substitution in Bash.

paste -d, <(printf 'Ana\nBob\n') <(printf '7\n12\n')

Example output:

Ana,7
Bob,12

Unlike join, which matches rows by a common key, paste aligns lines by position. If one input has fewer lines, the missing fields are filled with empty values. In environments that do not support process substitution, such as POSIX-only shells, prepare the two inputs as temporary files.

Main Options and Format

Options/Format Description
-d list Specifies the delimiter to use at the joining position.
-s Combines lines from each file sequentially into one line.
- Uses standard input in place of file arguments.

Precautions when using

First, check whether the corresponding lines of two files refer to the same object. If the line order is different, incorrect values may be placed side by side without causing an error. If you need to join lines using a common key, check the sorting condition and then use join.

Frequently Asked Questions

What is the difference between paste and join?

paste attaches lines according to their line numbers, while join connects lines that have the same value in a common field.

Official Documentation

You can check the exact behavior of the options and the differences between implementations in the official documentation on paste.

More in This Category
Linux more Command: View Text One Screen at a Time

Linux more Command: View Text One Screen at a Time

Learn how to use Linux more to read text one screen at a time, move and search interactively, start at a line or pattern, and choose between more and less.

Linux umount Command: Unmount a Filesystem Safely

Linux umount Command: Unmount a Filesystem Safely

Learn how to unmount a Filesystem Safely with the Linux umount command, including practical examples, key options, and important precautions.

Linux timedatectl Command: Check Time Zone and Time Synchronization

Linux timedatectl Command: Check Time Zone and Time Synchronization

Learn how to check Time Zone and Time Synchronization with the Linux timedatectl command, including practical examples, key options, and important precautions.

Linux nslookup Command: Query DNS Names and Records

Linux nslookup Command: Query DNS Names and Records

Learn how to query DNS Names and Records with the Linux nslookup command, including practical examples, key options, and important precautions.

Linux tr Command: Translate and Delete Characters

Linux tr Command: Translate and Delete Characters

Learn how to translate and Delete Characters with the Linux tr command, including practical examples, key options, and important precautions.

Linux Tutorial / Navigate Directories with pwd, ls, cd, and tree

Linux Tutorial / Navigate Directories with pwd, ls, cd, and tree

Use pwd, ls, cd, and tree to find your current location, inspect directories, navigate paths, and check where each command takes you.

Linux traceroute Command: Trace Routers on the Way to a Host

Linux traceroute Command: Trace Routers on the Way to a Host

Learn how to trace Routers on the Way to a Host with the Linux traceroute command, including practical examples, key options, and important precautions.

Linux apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux column Command: Format Text as a Table

Linux column Command: Format Text as a Table

Learn how to format Text as a Table with the Linux column command, including practical examples, key options, and important precautions.

Linux fg Command: Bring a Shell Job to the Foreground

Linux fg Command: Bring a Shell Job to the Foreground

Learn how to bring a Shell Job to the Foreground with the Linux fg command, including practical examples, key options, and important precautions.