cut
Text processing
Usage
cut -d, -f2 [file]Slices out fixed fields or character positions; the delimiter is a single character and repeated delimiters are not merged, so whitespace-aligned columns are awk's job.
Common flags
| Flag | Meaning |
|---|---|
| -d | The delimiter, exactly one character |
| -f | Which fields to keep, as in -f1,3 or -f2- |
| -c | Keep character positions instead of fields |
| -b | Keep byte positions |
| -s | Drop lines that contain no delimiter at all |
| -w | BSD and macOS: use runs of whitespace as the delimiter |
| --complement | GNU: keep everything except the selection |
Examples
cut -d: -f1 /etc/passwdEvery user name.
cut -c1-8 access.logThe first eight characters of each line.
cut -d, -f2- data.csvEverything from the second column on.
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does cut do?
Slices out fixed fields or character positions; the delimiter is a single character and repeated delimiters are not merged, so whitespace-aligned columns are awk's job.
Q. How do I type it?
cut -d, -f2 [file] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
7 are listed here; the full set is in man cut. This command sits under Text processing.
Related commands
man page: man cut