cut

Select specific bytes, characters, or fields from each input line.

What it does

cut extracts chosen parts of each line from a file or standard input. It is especially useful for pulling out columns from delimiter-separated text such as CSV-like files, passwd entries, and command output.

Quick Start

# First field, colon-delimited
cut -d ':' -f 1 /etc/passwd

# First and third fields, comma-delimited
cut -d ',' -f 1,3 data.csv

Examples

# Extract username field
cut -d ':' -f 1 /etc/passwd

# Extract columns 1 through 8 by character position
cut -c 1-8 report.txt

# Extract bytes 1-16
cut -b 1-16 binaryish.txt

# Extract multiple fields
cut -d ',' -f 2,4,5 sales.csv

# Preserve lines with no delimiter unchanged
cut -d ':' -f 1 --only-delimited /etc/passwd

Notes