Syntax
Description
Thecut command extracts specific fields or character positions from each line of input. It’s essential for working with structured text like CSV files, tab-separated data, or fixed-width columns.
Nash’s cut supports both field-based and character-based extraction with flexible range specifications.
Options
Select only these fields from each line. Field numbering starts at 1.Formats:
1- Single field1,3,5- Multiple specific fields1-3- Range of fields (1 through 3)2-- From field 2 to end (up to position 1000)
Use specified delimiter to separate fields. Defaults to tab character.Only the first character of the delimiter string is used.
Select only these character positions from each line. Position numbering starts at 1.Uses same format as
-f: 1, 1,3,5, 1-3, 2-You must specify either
-f (fields) or -c (characters), but not both.Examples
Extract single field
Extract multiple fields
Field range
Custom delimiter (CSV)
Extract characters
Specific character positions
From position to end
Pipeline Examples
Extract column from CSV
Process multiple files
Combine with grep
Pipeline transformation
Extract and count
Practical Use Cases
Parse /etc/passwd format
Extract email domains
Process log files
CSV to specific columns
Extract initials
Fixed-width data
Create new format
Working with Different Formats
Tab-separated (TSV)
-d needed.
Pipe-delimited
Space-delimited
Colon-delimited
Advanced Examples
Multi-stage extraction
Extract and filter
Join columns from multiple sources
Range to end
Tips
Field numbering starts at 1: The first field is
1, not 0. This matches standard Unix cut behavior.Delimiter output
Cut preserves the original delimiter in output:Open-ended ranges
UseN- to select from field N to the end:
Character vs field modes
- Field mode (
-f): Splits by delimiter, extracts fields - Character mode (
-c): Counts characters, extracts positions
