paste - macOS


Overview

paste is a versatile command-line utility that allows you to manipulate and paste text content on macOS. It’s commonly used to combine multiple text sources, filter text, or redirect text output for further processing.

Syntax

paste [-s | -d DELIM] [-o LIST] FILE_LIST

Options/Flags

  • -s: Concatenate files horizontally, appending lines side-by-side.
  • -d DELIM: Specify a delimiter to separate fields when concatenating files horizontally. Default: tab.
  • -o LIST: Specify a list of columns to output. Use -o 1-3 to output columns 1, 2, and 3 only.

Examples

Horizontal Concatenation:

paste -s file1 file2 file3

Horizontal Concatenation with Delimiter:

paste -d "," file1 file2 file3

Vertical Concatenation:

paste - column1.txt column2.txt

Column Selection:

paste -o 1-3 file1 file2 file3

Common Issues

  • Missing Files: Ensure that all specified files exist and are readable.
  • Improper Delimiter: If the delimiter is not specified correctly, fields may be misaligned.
  • Version Differences: Use paste -version to check your macOS version. Some options may not be supported on older versions.

Integration

grep Combination:

cat file1 file2 | paste -s | grep "pattern"

awk Combination:

paste -d "," file1 file2 | awk -F, '{print $1, $2}'
  • pboard: Accesses the system clipboard
  • cat: Concatenates and prints files
  • grep: Searches text for patterns