Skip to content
Latchkey

paste -d: Merge Files Side by Side

paste merges files column-wise, joining the Nth line of each file with a delimiter you pick via -d.

paste is the column-wise counterpart to cat: it places files next to each other rather than one after another.

What it does

paste reads the files in parallel and outputs, for each line number, the corresponding lines from every file joined by a delimiter (default TAB). -d sets the delimiter; if you give -d a string, paste cycles through its characters between successive columns.

Common usage

Terminal
paste names.txt ages.txt                 # tab-joined columns
paste -d, names.txt ages.txt             # CSV-style join
paste -d':' a.txt b.txt c.txt
paste -d'=\n' keys.txt vals.txt          # cycle through = and newline

Options

FlagWhat it does
-d <list>Delimiter(s); cycles if more than one character
-sSerial: one file per line instead of side by side
file1 file2 ...Files to merge column-wise
-Read stdin as one of the inputs

In CI

paste -d, builds a CSV from separate single-column files, for example pairing a list of keys with a list of values. The multi-character -d cycling trick lets you interleave a key and value with different separators.

Common errors in CI

If the files have different line counts, paste pads the shorter ones with empty fields up to the longest, so rows beyond the short file are missing a column rather than erroring. The default delimiter is a literal TAB, not a space, which can look like a single column in editors. -d takes a set of characters it cycles through, so -d', ' alternates comma and space, not "comma-space".

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →