When to use cut
Use cut to extract fixed character positions or explicitly separated fields. It is a good fit for simple records; whitespace-aligned tables and quoted CSV usually require a more capable parser.
Syntax
cut [OPTIONS] [FILE...]Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Show logins
cut -d: -f1 /etc/passwdThe first colon-delimited field lists account names.
Select two fields
cut -d: -f1,3 /etc/passwdThe first and third fields produce account names and numeric user IDs.
Select character positions from each line
cut -c1-20 ./report.txtThe beginning of each line is extracted; character and byte handling can depend on the implementation and locale.
Notes and limitations
- The -d delimiter consists of one character; consecutive spaces are not collapsed.
- For complex CSV and Unicode processing, check the utility's limitations and use a suitable parser.
Common questions and troubleshooting
Why do repeated spaces create unexpected fields?
A literal delimiter separates every occurrence; it does not collapse variable whitespace. Use awk when whitespace-separated columns are intended.
Can cut select columns from complex CSV?
Not reliably when delimiters occur inside quoted fields. Use a parser that understands CSV quoting and record boundaries.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man cut.