paste(1)
Merge lines of files side-by-side, combining corresponding lines with a delimiter.
Synopsis
paste [OPTION]... [FILE]...Description
The paste command concatenates lines from multiple files horizontally (side-by-side) rather than vertically. By default, it joins corresponding lines from each file with a tab character, creating columnar output useful for combining related data.
If no files are specified, or if - is given as a filename, paste reads from standard input. This allows piping data directly into the command.
Common options
| Flag | What it does |
|---|---|
-d DELIM | Use DELIM as the field separator instead of tab; can specify multiple delimiters to cycle through |
-s | Paste one file at a time (serial mode) instead of merging across files |
-z | Use NUL character as line terminator instead of newline |
Examples
Combine corresponding lines from two files side-by-side, separated by tabs
paste file1.txt file2.txtJoin three files with comma as the delimiter between columns
paste -d ',' file1.txt file2.txt file3.txtMerge names and ages, separating columns with a colon
paste -d ':' names.txt ages.txtRead from stdin and merge each line with itself (creates pairs of words)
cat data.txt | paste -d ' ' - -Join all lines of a file into a single output (no actual side-by-side effect here)
paste -s -d '\n' list.txtAlternate delimiters: tab, pipe, tab between columns
paste -d '\t|\t' first.txt last.txtConvert newline-separated list of filenames into comma-separated values
ls *.txt | paste -sd ',' -