The cut Command
Data comes in columns. CSV files, log entries, config files - all have structure.
cut extracts specific columns from text.
Cut by Delimiter
Most useful: split by a character and pick fields:
-d':'= delimiter is:-f1= first field-f6= sixth field
Multiple Fields
-f1,3= fields 1 and 3-f1-3= fields 1 through 3
CSV Processing
Quoted CSV
cut doesn't handle quoted fields properly. For proper CSV with quotes, use awk or a dedicated CSV tool.
Cut by Character Position
-c1-5= characters 1 through 5-c1,3,5= characters 1, 3, and 5
Real-World Examples
Extract Usernames from /etc/passwd
Get Column from Log File
Parse PATH Variable
(Here tr is better since PATH uses : but we want each path on its own line.)
The Default Delimiter
Without -d, cut uses TAB as the delimiter:
Complement (Everything Except)
--complement gives you everything except the specified fields.
How do you extract the third field from a colon-separated file?
Key Takeaways
-dsets the delimiter-fselects fields (1-indexed)-cselects character positions- Use
-f1,3,5for specific fields - Use
-f1-5for ranges - Default delimiter is TAB
cutis simple but doesn't handle complex CSV
Next: sorting lines with sort.