cut From Zero: Slicing Columns Out of Lines
cut does one thing: split each line into fields on a delimiter and output the fields you ask for. This guide runs every command for real on GNU coreutils 9.4 — field lists and ranges, CSV and output delimiters, character slicing, --complement, the -s rule for lines without a delimiter, log-column statistics, and the quoted-comma limit — with the output pasted verbatim.

Once you have found the lines, the next step is usually to pull a few columns out of them: just the usernames and shells from /etc/passwd, just the name and English score from a grade table, just the time and level from a log. The tool for slicing columns is cut: it does exactly one thing — split each line into fields on a delimiter, then output the fields you asked for. Together with the grep guide from this same cycle, two steps cover the most common text-processing pipeline: grep finds the lines first, cut slices the columns out of them. Every command in this article was run for real on GNU coreutils 9.4 (bash 5.2.21), and the output is pasted verbatim — type it in and you will get exactly the same result. First, three demo files: users.txt (5 lines in /etc/passwd-style colon-separated format), scores.csv (4 lines of comma-separated grades), and access.log (3 lines of space-separated log entries).
$ cat users.txt root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin alice:x:1000:1000:Alice:/home/alice:/bin/bash bob:x:1001:1001:Bob:/home/bob:/bin/zsh carol:x:1002:1002:Carol:/home/carol:/bin/bash $ cat scores.csv name,math,english,science anna,92,88,95 ben,78,85,80 cara,95,91,93 $ cat access.log 2026-11-30 10:15:02 INFO server started 2026-11-30 10:16:44 WARN disk 91 percent full 2026-11-30 10:18:09 ERROR worker-3 lost heartbeat
cut is a member of GNU coreutils, from the same toolset as ls, cat, and sort; it exists on any Linux machine, needs no installation and no new language to learn. Someone might ask: awk can slice columns too, so why have cut at all? The answer is division of labour: awk is a complete text-processing language that can compute, decide, and rearrange; cut does only column slicing, with short commands, obvious intent, and a small surface for mistakes. The simpler the task, the simpler the tool should be — the same idea behind both this cycle's grep guide and this cut guide: master "find lines" and "slice columns" first, then learn the bigger tool that is awk.
1. The basic form: cut -d delimiter -f field
The basic form is cut -d delimiter -f field-number file: -d says which character to split on (the delimiter), -f says which field to take. users.txt mimics /etc/passwd: colon-separated, seven fields — username, password placeholder x, user ID, group ID, full name, home directory, login shell. First, just field 1, the usernames:
$ cut -d: -f1 users.txt root daemon alice bob carol exit=0
Fields are counted from 1, not 0 — the mistake cut beginners make most often; anyone used to programming languages will instinctively type -f0, and cut will refuse. Several fields are joined with commas, for example the username and the shell (fields 1 and 7):
$ cut -d: -f1,7 users.txt root:/bin/bash daemon:/usr/sbin/nologin alice:/bin/bash bob:/bin/zsh carol:/bin/bash exit=0
Note that the output fields are still joined with colons: by default cut re-joins the output fields with the input delimiter. To change the output separator, use --output-delimiter, covered in section 3. Remember how cut works: it reads the file line by line, splits each line on the delimiter, picks the fields you asked for, and joins them back into one output line; the number of lines stays the same, only each line gets shorter. That contrasts with grep: grep picks lines, cut picks columns.
cut can also read from standard input with no filename: echo "a:b:c" | cut -d: -f2 prints b. That lets cut sit inside any pipeline — the previous command's output becomes its input. Several places in this article's demo use exactly that, in the form printf ... | cut. In scripts, prefer pipes over temporary files: one fewer disk write, and one fewer intermediate file to clean up.
2. Ranges and order: -f3-, -f-2, -f7,1
Field selection supports three spellings: a single field (-f1), a list (-f1,7), and ranges. There are two open-ended range spellings: -f3- means "from field 3 to the end of the line", and -f-2 means "from the start of the line to field 2". First, everything from field 3 onward:
$ cut -d: -f3- users.txt (field 3 to the end) 0:0:root:/root:/bin/bash 1:1:daemon:/usr/sbin:/usr/sbin/nologin 1000:1000:Alice:/home/alice:/bin/bash 1001:1001:Bob:/home/bob:/bin/zsh 1002:1002:Carol:/home/carol:/bin/bash exit=0
The username and password placeholder are gone, leaving everything from the user ID onward. Now from the start of the line to field 2:
$ cut -d: -f-2 users.txt (from the start to field 2) root:x daemon:x alice:x bob:x carol:x exit=0
Middle ranges work too: -f2-4 means fields 2 through 4. Ranges and lists can be mixed, for example -f1,3-5,7. There is one rule that surprises people: the order you write in -f does not change the output order — output always follows the fields' original order in the line. Writing -f7,1 still puts the username first and the shell second:
$ cut -d: -f7,1 users.txt (order in the list is ignored: output keeps file order) root:/bin/bash daemon:/usr/sbin/nologin alice:/bin/bash bob:/bin/zsh carol:/bin/bash exit=0
To put the shell before the username, cut cannot help — it does not reorder fields, it only selects them. That is one of the dividing lines with awk: awk can print $7, $1 and arrange fields any way you like, cut cannot. If all you need is "pick a few columns out", cut is simpler; if you need reordering, regrouping, or computing, that is awk's job (this site already has an awk guide).
A middle range written directly looks like this:
$ cut -d: -f2-4 users.txt (fields 2 through 4) x:0:0 x:1:1 x:1000:1000 x:1001:1001 x:1002:1002 exit=0
Fields 2 through 4 are the password placeholder, the user ID, and the group ID, taken out in one go. Ranges and lists mix freely — -f1,3-5,7 means field 1, fields 3 to 5, and field 7 — shorter to write than listing every number, and harder to leave one out by accident.
3. Changing delimiters and the output delimiter: CSV in practice
The delimiter does not have to be a colon. The grade table scores.csv is comma-separated; taking the maths and English columns (fields 2 and 3):
$ cut -d, -f2,3 scores.csv math,english 92,88 78,85 95,91 exit=0
The first line is the header, and it gets sliced along with everything else — cut does not know what a header is; it treats every line as an ordinary data row. In practice, if you want the data without the header, strip the first line first with tail -n +2 and then hand the rest to cut (the head-tail guide covers tail -n +2):
$ tail -n +2 scores.csv | cut -d, -f1,3 (skip the header line first) anna,88 ben,85 cara,91 exit=0
The header is gone, leaving three rows of data. The order in the pipeline matters: tail first, cut second — filter out the unwanted lines first, then slice the columns you want. Writing it the other way round (slice first, drop the header after) gives the same result, but filtering first and processing second is the tidier habit — the less data later commands handle, the fewer chances for mistakes.
--output-delimiter changes what joins the output fields. Taking just the name and English score, joined with | , makes the output immediately readable:
$ cut -d, -f1,3 --output-delimiter=' | ' scores.csv name | english anna | 88 ben | 85 cara | 91 exit=0
Two details to note: first, --output-delimiter only changes how the output is joined, not how the input is parsed — the input is still split on -d,; second, the header row name | english gets the new separator too, because it is also a sliced data row. This option is especially useful when generating reports, assembling Markdown tables, or feeding results into a next command that expects a particular separator.
4. Slicing by character: -c, for fixed-width text
Besides splitting on a delimiter, cut can slice by character position: -c (character) cuts on character numbers. Taking the first 8 characters of each line:
$ cut -c1-8 users.txt (first 8 characters of each line) root:x:0 daemon:x alice:x: bob:x:10 carol:x: exit=0
Look closely at these five lines: each is exactly 8 characters long, but the content differs — the daemon line is just daemon:x (8 characters), while the bob line is bob:x:10 (its 8th character is the 0 after the 1). Character slicing ignores delimiters and only looks at positions, so the same column can slice out completely different things on different lines. The range spellings work just like -f: -c1-8, -c5-, -c-3, and -c1,5,9 are all valid.
When should you use -c instead of -f? Two situations: first, fixed-width text, such as the fixed-column reports exported by older systems, where characters 1–10 are the employee number and characters 11–30 are the name — with no delimiter at all, position is the only way to cut; second, taking a prefix, such as cut -c1-7 for a seven-character summary of each line. In the other direction, delimiter-separated text (passwd, CSV, logs) should always prefer -f, because field lengths change and position slicing will eventually cut in the wrong place. One more detail: -c counts characters, not bytes — under a UTF-8 locale, one Chinese character counts as one character; but under LC_ALL=C, cut counts bytes, one Chinese character takes 3 bytes, and -c1-8 can slice out two and a half characters. Before searching or slicing Chinese text, confirm the locale is UTF-8 — the same warning as section 10 of the grep guide.
Closely related to -c is -b (byte, slice by bytes): on pure ASCII text, -b and -c give identical results; once the text contains multi-byte characters such as Chinese, they part ways — -c1-8 takes 8 characters, -b1-8 takes only 8 bytes, which is barely more than two Chinese characters. -c is enough for everyday use; -b only earns its keep when handling byte-aligned binary data or fixed-width byte streams. Remembering this distinction saves you from wondering "why is my Chinese text cut in half".
5. Inversion and -s: --complement and lines without a delimiter
--complement inverts the selection: it outputs every field except the ones you named. Dropping the username and keeping the rest:
$ cut -d: -f1 --complement users.txt (everything except field 1) x:0:0:root:/root:/bin/bash x:1:1:daemon:/usr/sbin:/usr/sbin/nologin x:1000:1000:Alice:/home/alice:/bin/bash x:1001:1001:Bob:/home/bob:/bin/zsh x:1002:1002:Carol:/home/carol:/bin/bash exit=0
Inversion saves a lot of typing when there are many fields and you only want to drop one or two: if a log has 12 columns and you only want to drop the timestamp in column 5, --complement -f5 is far shorter than listing the other 11 columns one by one.
--complement also mixes with ranges and lists: cut -d: -f2-4 --complement users.txt outputs every field except fields 2 to 4 — the username, then everything after the group ID. Note that --complement modifies the -f (or -c, or -b) selection and belongs in the same command; writing cut --complement on its own with no field selection fails, because cut does not know what to invert.
Another trap is what happens to lines without a delimiter: by default, cut prints them unchanged. Testing with two lines, a:b:c and plainline:
$ printf "a:b:c\nplainline\n" | cut -d: -f2 (no delimiter: line printed whole) b plainline exit=0
Field 2 of a:b:c is b, as expected; but plainline contains no colon at all, and cut still printed it whole. That is not a bug — it is the POSIX-specified default: a line with no delimiter is considered "not splittable" and passed through whole. Many people get bitten by this in pipelines: they only wanted column 2, and a pile of whole lines slipped through as dirty data. The fix is -s (--only-delimited): lines without the delimiter are dropped outright:
$ printf "a:b:c\nplainline\n" | cut -d: -f2 -s (-s drops lines without the delimiter) b exit=0
Now only b remains. The rule to remember: when slicing columns out of unreliable input, always add -s, unless you explicitly want to keep the lines that have no delimiter.
6. In practice: taking columns from logs, then counting
Putting the earlier sections together gives the most common everyday use: taking columns out of logs. access.log is space-separated: date, time, level, message. Taking just the time column (field 2):
$ cut -d' ' -f2 access.log (the time column) 10:15:02 10:16:44 10:18:09 exit=0
The delimiter is a space, so it must be quoted as -d' ', or the shell will treat the space as an argument separator. Now the date and the level (fields 1 and 3):
$ cut -d' ' -f1,3 access.log (date + level) 2026-11-30 INFO 2026-11-30 WARN 2026-11-30 ERROR exit=0
The level of all three log lines is visible at a glance. Going further, cut's output feeds straight into a pipeline for statistics. Counting which shells are in use in users.txt: slice out field 7, sort, then count each distinct value:
$ cut -d: -f7 users.txt | sort | uniq -c (which shells are in use)
3 /bin/bash
1 /bin/zsh
1 /usr/sbin/nologin
exit=0
Three people use bash, one uses zsh, one is nologin (the daemon account is not allowed to log in). This cut | sort | uniq -c combination is a classic shell statistics pattern; the sort+uniq guide covers it in full, and cut's role here is to extract the one column to be counted, cleanly, for the commands after it. If a column contains several space-separated words, pick the right delimiter with -d first — otherwise the columns shift, and the statistics shift with them.
Finally, the two guides in this cycle working together: grep finds the lines, cut takes the columns. To find out when the ERROR log line happened:
$ grep ERROR access.log | cut -d' ' -f2 (grep finds the line, cut takes the column) 10:18:09 exit=0
grep filtered three log lines down to one, and cut took field 2 (the time) out of it. That is the standard "grep finds, cut slices" pipeline: the first part narrows the scope, the second extracts the information. Both commands are short, yet together they answer a concrete question — "when did the error happen?"; add sort | uniq -c after them and you can answer "how many errors per hour?". Each stage of a pipeline does one thing, which is what keeps the whole pipeline readable, editable, and debuggable.
7. Limits: the comma inside quotes, which cut cannot see
cut's biggest limitation is that it has no notion of "quotes" at all. In the CSV standard, a field's content can be quoted, and a comma inside quotes is not a separator: in the line doe,"smith, john",42, the real field 2 is smith, john (a person's name, with a comma between surname and given name). But cut only sees commas:
$ printf "doe,\"smith, john\",42\n" | cut -d, -f2 (quoted comma: cut cannot see the quotes) "smith exit=0
What comes out is "smith — a fragment cut in half, the opening quote still there, the , john" treated as the next field. That is not user error; it is cut's design boundary: it only splits on a single character and understands no quoting or escaping rules. Real-world CSV files often contain quotes, embedded newlines, and escapes; those need a real CSV parser: Python's csv module (python3 -c "import csv..."), Miller (mlr), or xsv. The rule is simple: if your CSV file has ever contained a double quote, do not use cut; if you are sure there are no quotes and no commas nested inside fields, cut is safe.
cut's other limits are worth stating once, clearly: the delimiter can only be a single character, never several (no :: or , as a delimiter); it cannot reorder fields (section 2); it cannot make conditional decisions (such as "only output rows where field 3 is greater than 90"); it cannot split on a regular expression. Those needs belong to awk, Python, or a specialised tool. cut's job is "simple, fast, dependency-free column slicing", and it does that job well; beyond that job, switch tools instead of forcing it.
A quick decision table: if the job is "take a few columns on a delimiter", use cut; if it is "reorder fields, compute by column, filter by condition", use awk; if it is "parse quoted CSV, handle JSON, handle multi-line records", use Python or a dedicated tool. The deciding principle is not "which tool is more powerful" but "which tool makes this command shortest and most obvious" — three months later, when you come back to that pipeline, being able to see at a glance what it does matters more than how advanced the tool was. cut commands are usually a dozen characters long, and that is exactly why cut exists.
8. Scope: grep finds lines, cut slices columns, awk computes
Stringing this site's text-processing guides together gives a clear division of labour: grep does "finding lines" (this cycle's grep guide), cut does "slicing columns" (this article), awk does "computing by column, grouping, conditional decisions" (this site already has an awk guide), sed does "rewriting and replacing" (this site already has a sed guide), and sort+uniq does "sorting, deduplicating, counting" (this site already has a sort+uniq guide). The head-tail guide covers taking the head and tail of a file, the tee guide covers splitting output, and the shell pipes guide covers chaining these commands with |. When a text-processing task arrives, first ask which step it is: finding lines means grep, slicing columns means cut, rewriting means sed, computing means awk — using the simplest tool for each step keeps the whole pipeline readable, editable, and debuggable.
Scope against this cycle's grep guide: that one covers "finding", this one covers "slicing", and the two demo files and command sets do not overlap; against the text-processing overview: the overview mentions cut in a single sentence ("cut slices columns"), and this article is the full deep dive. On the banned list: this article touches none of the used lines — no Python single-module guides, curl, find/xargs, sed, awk, or git; chmod is covered by the linux-file-permissions guide and is not touched here. After these two guides, the two most common text-processing moves are covered: grep finds the lines, then cut slices the columns; sed and awk handle the rewriting and computing that remain.
9. Common mistakes
Finally, five traps beginners hit most often. First, forgetting -d: cut's default delimiter is TAB, not space or comma — running plain cut -f2 file on a space-separated log slices nothing, because the file contains no TAB at all. Second, -d takes only a single character: cut -d', ' -f2 does not split on "comma plus space"; it only takes the first character as the delimiter (different versions of cut handle a multi-character -d differently — some error, some silently take the first character), so for a multi-character delimiter use awk's -F', ' or a sed replacement first. Third, field numbers start at 1: -f0 is wrong, and cut will error. Fourth, --output-delimiter only affects output: it never changes how the input is parsed — parsing is always decided by -d, as section 3 explained, but worth repeating because it is the most confused point. Fifth, different lines can have different field counts: cut splits each line independently, so if one line has two fewer fields than the others, the field you want simply does not exist on that line — cut will not error, it will just output an empty line or one column short. When handling unreliable data, first find the lines with the wrong field count, for example with awk -F: 'NF!=7', which is faster than staring at misaligned output afterwards.
10. Cheat sheet and exercises
cut -d: -f1 FILE take field 1 (colon-separated) cut -d: -f1,7 FILE take fields 1 and 7 cut -d: -f3- FILE from field 3 to the end of the line cut -d: -f-2 FILE from the start of the line to field 2 cut -d: -f2-4 FILE take fields 2 through 4 cut -d, -f1,3 --output-delimiter=' | ' FILE change the output delimiter cut -c1-8 FILE take the first 8 characters of each line cut -d: -f1 --complement FILE everything except field 1 cut -d: -f2 -s FILE only lines containing the delimiter cut -d' ' -f2 FILE space-separated, take column 2 cut -d: -f7 FILE | sort | uniq -c count the distribution of one column
Practice: first set yourself a small goal — next time you need a column out of some text, ask whether cut can do it before opening an editor to copy by hand. Then run these three commands on your own machine: cut -d: -f1,7 /etc/passwd (who is on the system, and which shell do they use), cut -d' ' -f1 access.log | sort | uniq -c (which day has the most requests — swap access.log for a real log file you have), and history | cut -c8- | sort | uniq -c | sort -rn | head -10 (your 10 most-used commands — cut -c8- strips the line numbers from the start of each history line, leaving just the command). After those three, you will have the feel of cut.
One more combined exercise, tying this cycle's two guides together: take a real log you have (say an Nginx access.log) and run grep ' 404 ' access.log | cut -d' ' -f1,7 | sort | uniq -c | sort -rn | head -10 to see which URLs return 404 most often — grep filters to the 404 lines, cut takes the date and URL columns, sort plus uniq -c counts them, and the final sort shows the top ten by frequency. Run it once and you will have practised grep and cut together, and learned something about the health of your own service. If an awk guide comes next, it will cover the half cut cannot do: computing by column, conditional filtering, and field reordering.
Comments (0)
Sources
Related articles
cron is the scheduling daemon that has run on Linux for decades: write a crontab file saying 'run this command at this time', and it handles the rest. This guide runs everything for real on Debian cron 3.0pl1-162 — installing a job, waiting one minute for the trigger, verifying the log, removing the job — plus special strings, five classic mistakes, and a real 3 a.m. log-archiving job.
ping does exactly one thing: send an ICMP echo request, wait for the echo reply, and report the round-trip time and packet loss. This guide runs every command for real on iputils ping 20240117 — packet count, interval, quiet mode, packet size, timestamps, IPv4 vs IPv6, the three failure modes, exit codes 0/1/2 — with output pasted verbatim.
grep does one thing: find lines in text that match a pattern. This guide runs every command for real on GNU grep 3.11 — line numbers, case-insensitive search, recursion, context lines, whole-word matching, the three pattern modes (BRE, -E, -F), anchors and alternation, quiet mode for scripts, and binary files — with the output pasted verbatim.