Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français

cut: extract columns

By updated

Improve this page

When you need to quickly extract a column from a CSV file, fetch a field from a configuration file or isolate part of a log line, cut is the ideal tool. Simple and fast, cut extracts portions of text by position (characters) or by field (delimiter), straight from the command line.

What you will learn

  • Extract columns by position with -c (characters)
  • Extract fields with a delimiter with -f and -d
  • Use ranges (1-5, 3-, -10)
  • Combine cut with other commands (grep, sort, uniq)

The cut command in the Linux ecosystem

cut belongs to the text-processing commands of Linux. Each tool has its speciality, and cut is the most limited of them, which is also what makes it the fastest to write:

CommandSpecialityWhen to use it
cutExtract columns/fieldsSimple delimited files (CSV, TSV, passwd)
awkAdvanced column processingCalculations, conditions, complex formats
sedEdit text as a streamReplace, delete, insert
grepFilter linesSearch for patterns
trTransliterate charactersReplace character by character
pasteMerge filesJoin columns side by side

When to use cut vs awk?

The table below sums up the cases where cut is enough and the ones where awk is required, depending on the shape of the data:

Situationcutawk
Extract a simple columnYes, cut -d',' -f2Yes, but overkill
Single, fixed delimiterYes, ideal caseYes
Multiple spaces as delimiterNoYes, awk '{print $2}'
CSV with quotesNoYes (or csvtool)
Reorder columnsNoYes, awk '{print $3,$1}'
Calculations on columnsNoYes, awk '{sum+=$2}'

Frequent combinations:

Terminal window
# grep + cut: filter then extract
grep 'admin' users.csv | cut -d',' -f2
# cut + sort + uniq: count the values of a column
cut -d',' -f4 users.csv | sort | uniq -c
# cut + xargs: run a command on each value
cut -d':' -f1 /etc/passwd | xargs -I{} id {}

Understand the cut command in 2 minutes

The mental model below sums up how cut works: an input, an extraction mode, an output.

🧠 Mental model: How cut works

cut = Pick the mode → Say what to extract → Get the result

cut reads its input line by line, applies an extraction mode (-c characters, -f fields, -b bytes) and writes the extracted columns to standard output; -d sets the delimiter and --complement inverts the selection.cutINPUTfile · stdin, line by lineEXTRACTION MODE-c characters · -f fields · -b bytesOUTPUTextracted columns on stdout-d',' delimiter · -f1,3 fields--complement inverts the selection
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

Key points

  • cut extracts parts of each line (columns, characters or fields)
  • -c for characters (position), -f for fields (with a delimiter)
  • By default, the delimiter is the tab (\t)
  • Use -d to set another delimiter (comma, colon...)
  • Ranges: 1-5 (from 1 to 5), 3- (from 3 on), -10 (up to 10)
  • cut does not modify the file, it prints to stdout

Golden rules

1
Always set -d when the delimiter is not a tab By default cut uses TAB. For a CSV, use -d','
2
Prefer awk for complex cases cut is limited: a single delimiter, no regex, no calculations

Essential vocabulary

-c1-10
Characters 1 to 10
-f2
Field number 2
-d','
Comma delimiter
-f1,3,5
Fields 1, 3 and 5
-f2-
From field 2 to the end
--complement
Inverts the selection
📚 Going further: 6 advanced options
-b
Extraction by bytes (can split a UTF-8 character)
-s
Only prints lines containing the delimiter
--output-delimiter
Changes the output delimiter
-f-3
From the start up to field 3
-f1,3-5,7
Mix of fields and ranges
-c1,5,10
Specific characters (non-contiguous)

cut reads the file line by line, splits it according to the chosen mode (characters or fields), then prints the selected portions on stdout.

Minimal syntax

The signature is deliberately poor: no option has a useful default value. Without -f, -c or -b, cut refuses to work and returns you must specify a list of bytes, characters, or fields. If you leave out the file, cut reads stdin, which makes it a natural link in a pipeline.

Terminal window
cut [OPTIONS] [FICHIER]

The 2 extraction modes

cut offers two main modes, and the choice comes down to a single question: are the columns separated by a constant character, or aligned at a constant position? A CSV, an /etc/passwd or a TSV belong to the first case, a tabulated output with fixed width to the second.

ModeOptionUseExample
Fields-fDelimited files (CSV, TSV)cut -d',' -f2 data.csv
Characters-cFixed positionscut -c1-10 log.txt

Extraction by field (-f + -d)

It is the most common mode. You give the delimiter and the fields to keep, in two options:

  • -d'X': the delimiter (separator character)
  • -f N: the field(s) to extract
Terminal window
# CSV file (comma)
cut -d',' -f2 users.csv
# passwd file (colon)
cut -d':' -f1,7 /etc/passwd
# TSV file (TAB by default)
cut -f2 data.tsv

Important: without -d, cut uses the tab as its default delimiter, a frequent source of surprises on a CSV.

Selection ranges

The same range syntax applies to -f (fields) and -c (characters): what changes is the unit counted, not the grammar. Remember above all the two open forms, -f3- and -f-3: they are the ones that spare you from knowing the number of columns in advance. The lone dash (-f-) is refused, cut answers invalid range with no endpoint.

SyntaxMeaningExample
-f NField N only-f2 → 2nd field
-f N,M,PFields N, M and P-f1,3,5 → fields 1, 3, 5
-f N-MFrom N to M-f2-4 → fields 2, 3, 4
-f N-From N to the end-f3- → from the 3rd to the end
-f -NFrom the start to N-f-3 → fields 1, 2, 3

Extraction by character (-c)

Useful for fixed-width files (logs, mainframe exports). This mode completely ignores delimiters, to the point that cut refuses -d with -c: an input delimiter may be specified only when operating on fields. Count the positions on a real line, never on the header, whose alignment often differs from the data.

Terminal window
# The first 15 characters (IP address in a log)
cut -c1-15 access.log
# Characters 10 to 20
cut -c10-20 fichier.txt
# Specific characters (non-contiguous)
cut -c1,5,10 fichier.txt

Useful options

Three options save time without changing the extraction logic. --complement avoids listing twenty columns to drop a single one. -s protects automated processing: without it, a comment line or an empty line goes through cut untouched and pollutes the output. --output-delimiter separates the input delimiter from the output delimiter, useful to convert a CSV into a TSV.

OptionEffectExample
--complementInverts the selection-f3 --complement (everything but field 3)
-sSkips lines without a delimiter-d':' -f1 -s
--output-delimiterChanges the output delimiter--output-delimiter=';'

Typical errors (and fixes)

What these four situations have in common: cut reports nothing. It returns no error code when the requested field does not exist, nor when the delimiter is missing from the line. So it is the output you must inspect, never $?. Read the "Cause" column before the "Fix" column: in three cases out of four, the answer is to switch to awk, not to tinker with the options of cut.

ErrorCauseFix
The whole line is printedWrong delimiter or delimiter missingCheck with cat -A, use the right -d
Empty resultNon-existent field (number too high)Count the columns with head -1 | tr ',' '\n' | wc -l
Badly split columnsMultiple spaces or CSV quotesUse awk instead
Column order not respectedcut prints in file orderUse awk '{print $3,$1}'

Common extraction patterns

Now that you understand the logic of cut, here are twelve ready-to-use patterns. Each one gives its general formula and a concrete example.

Extract a field

Fetch a single column from a delimited file, the most frequent use of cut.

Terminal window
cut -d'DELIM' -f N <fichier> # formula
cut -d',' -f2 users.csv # example
  • DELIM: separator character (comma, colon…)
  • N: number of the field to extract (starts at 1)

Extract several fields

Fetch several precise columns with a comma-separated list.

Terminal window
cut -d'DELIM' -f N,M,P <fichier> # formula
cut -d':' -f1,7 /etc/passwd # example
  • N,M,P: list of fields separated by commas

Extract a range of fields

Fetch a series of consecutive columns with a range.

Terminal window
cut -d'DELIM' -f N-M <fichier> # formula
cut -d',' -f2-4 data.csv # example
  • N-M: from field N to field M inclusive

From field N to the end

Extract from one field to the last one, without knowing the number of columns.

Terminal window
cut -d'DELIM' -f N- <fichier> # formula
cut -d':' -f3- /etc/passwd # example
  • N-: from field N to the end of the line

From the start to field N

Extract from the first field up to field N, an open range.

Terminal window
cut -d'DELIM' -f -N <fichier> # formula
cut -d',' -f-3 data.csv # example
  • -N: from the start up to field N inclusive

Extract by position (characters)

Extract characters at fixed positions, in character mode.

Terminal window
cut -c N-M <fichier> # formula
cut -c1-15 access.log # example
  • -c: character mode (fixed position)
  • N-M: positions of the characters

TSV files (tab)

Extract columns from a file separated by tabs, the default delimiter.

Terminal window
cut -f N <fichier.tsv> # formula
cut -f2 data.tsv # example
  • -f without -d: uses the tab by default

Invert the selection

Print everything except the listed fields, with --complement.

Terminal window
cut -d'DELIM' -f N --complement <fichier> # formula
cut -d',' -f3 --complement users.csv # example
  • --complement: inverts the selection

Change the output delimiter

Use a different separator in the result, with --output-delimiter.

Terminal window
cut -d'DELIM1' -f N,M --output-delimiter='DELIM2' <fichier> # formula
cut -d',' -f1,3 --output-delimiter=$'\t' data.csv # example
  • --output-delimiter: delimiter applied to the output
  • cut interprets no escape sequence: --output-delimiter='\t' writes the two characters \ and t. For a real tab, use the shell's $'\t' syntax (bash, zsh)

Pipeline with grep

Filter the lines first, then extract the columns.

Terminal window
grep 'PATTERN' <fichier> | cut -d'DELIM' -f N # formula
grep ',admin,' users.csv | cut -d',' -f2 # example
  • grep filters first, cut extracts next

Pipeline with sort and uniq

Extract a column and count its unique values.

Terminal window
cut -d'DELIM' -f N <fichier> | sort | uniq -c # formula
cut -d',' -f4 users.csv | sort | uniq -c # example
  • sort | uniq -c: sorts then counts the occurrences

Skip lines without a delimiter

Only print the lines that actually contain the delimiter, with -s.

Terminal window
cut -d'DELIM' -f N -s <fichier> # formula
cut -d':' -f1 -s mixed.txt # example
  • -s: removes the lines without a delimiter from the output

Pitfalls to avoid

Six errors come back constantly with cut. For each one: the faulty command, the symptom, the cause and the correction.

Forgetting the delimiter (tab by default)

Without -d, cut looks for a tab that a CSV does not contain.

Terminal window
cut -f2 fichier.csv # WRONG: on a CSV, the whole line comes out

Symptom: the whole line is printed instead of the 2nd field. Cause: without -d, cut expects a tab, not a comma.

Terminal window
cut -d',' -f2 fichier.csv # RIGHT: explicit delimiter

Multiple spaces as delimiter

Aligned columns use several spaces, which cut cannot treat as a single separator.

Terminal window
cut -d' ' -f2 fichier.txt # WRONG: several spaces between columns

Symptom: empty or shifted results. Cause: cut treats a single space as the delimiter, never a run of spaces.

Terminal window
awk '{ print $2 }' fichier.txt # RIGHT: awk handles multiple spaces

CSV with quoted fields

A comma inside quotes remains a separator for cut.

Terminal window
cut -d',' -f2 fichier.csv # WRONG: "Alice, Bob",email: wrong split

Symptom: fields containing an inner comma are badly split. Cause: cut knows nothing about CSV quotes (RFC 4180).

Terminal window
awk -F'","' '{ print $2 }' fichier.csv # RIGHT if every field is quoted
csvtool col 2 fichier.csv # RIGHT in every case: a real CSV parser

The awk workaround only holds if every field is quoted: on 1,"Alice, Bob",email, the first field carries none and the split stays wrong. csvtool, a package of the same name on Debian, actually implements RFC 4180.

Fields come out in file order

The list order given to -f has no effect on the output order.

Terminal window
cut -d',' -f3,1 fichier.csv # WRONG: prints in order 1,3, not 3,1

Symptom: the order of the fields is not the one requested. Cause: cut always prints the fields in their order of appearance.

Terminal window
awk -F',' '{ print $3","$1 }' fichier.csv # RIGHT: awk reorders

Non-existent field

A field number beyond the last column gives an empty result and no error.

Terminal window
cut -d',' -f10 fichier.csv # WRONG: 5-column file, nothing comes out

Symptom: empty lines, no output. Cause: cut returns nothing if the field does not exist, without any error message.

Terminal window
head -1 fichier.csv | tr ',' '\n' | wc -l # RIGHT: count the columns first

Multi-byte UTF-8 characters

Character mode does not count the same unit on every distribution, and accented text reveals it.

Terminal window
cut -c1-5 fichier.txt # WRONG: on accented text, truncated characters

Symptom: characters cut or badly displayed. Cause: in GNU coreutils as Debian and Ubuntu ship it, -c is treated as -b, so it counts bytes. An accented character takes two of them in UTF-8, an emoji up to four. Setting LANG to a UTF-8 locale changes nothing: measured on Debian 13 (coreutils 9.7), cut -c1-5 on Écran returns Écra. RHEL and AlmaLinux on the other hand apply an internationalisation patch: under a UTF-8 locale, coreutils 9.5 on AlmaLinux 10 does return Écran. A script that must run everywhere therefore cannot rely on -c.

Terminal window
gawk '{ print substr($0, 1, 5) }' fichier.txt # RIGHT: gawk counts characters

Call gawk by name: on Debian and Ubuntu, the awk command is mawk by default, and it counts bytes too. Measured on Écran under a UTF-8 locale: mawk returns Écra, gawk returns Écran. Install it with apt install gawk if it is missing.

Hands-on lab

Nothing replaces practice. Create the test environment below, then go through the eight steps. At the end, clean up with rm -rf ~/cut-lab.

Prepare the ground

This script creates four test files in ~/cut-lab: a CSV, a TSV, a passwd-type file and a fixed-width log.

Terminal window
# Create the lab
mkdir -p ~/cut-lab
cd ~/cut-lab
# CSV file (comma)
cat > users.csv << 'EOF'
id,nom,email,role,salaire
1,Alice,alice@example.com,admin,5000
2,Bob,bob@example.com,user,3500
3,Charlie,charlie@example.com,user,3200
4,Diana,diana@example.com,moderator,4000
5,Eve,eve@example.com,admin,5500
EOF
# TSV file (tab)
cat > data.tsv << 'EOF'
Produit Prix Stock Catégorie
Laptop 999 50 Informatique
Souris 29 200 Périphériques
Clavier 79 150 Périphériques
Écran 299 75 Informatique
EOF
# passwd-type file (colon)
cat > passwd.txt << 'EOF'
root:x:0:0:root:/root:/bin/bash
bob:x:1000:1000:Bob User:/home/bob:/bin/bash
alice:x:1001:1001:Alice Admin:/home/alice:/bin/zsh
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
EOF
# Fixed-width log file
cat > access.log << 'EOF'
192.168.1.10 2025-01-15 GET /index.html 200
192.168.1.20 2025-01-15 POST /api/users 201
192.168.1.30 2025-01-15 GET /style.css 200
192.168.1.10 2025-01-15 GET /favicon.ico 404
EOF
echo "Lab créé dans ~/cut-lab"
ls -la ~/cut-lab

The eight steps

Each step adds one option to the previous one: a single field, several fields, a range, then the other file formats and the pipelines.

  1. Extract a CSV column. Extract the nom column (2nd field) from the users.csv file.

    Terminal window
    cut -d',' -f2 ~/cut-lab/users.csv

    -d',' sets the comma as the delimiter, -f2 selects the 2nd field. To skip the header: tail -n +2 ~/cut-lab/users.csv | cut -d',' -f2.

  2. Extract several columns. Extract the nom and email columns (fields 2 and 3) from users.csv.

    Terminal window
    cut -d',' -f2,3 ~/cut-lab/users.csv

    -f2,3 selects fields 2 and 3.

  3. Extract a range of columns. Extract columns 2 to 4 (nom, email, role) from users.csv.

    Terminal window
    cut -d',' -f2-4 ~/cut-lab/users.csv

    -f2-4 selects fields 2 to 4 inclusive.

  4. Tab-separated file (TSV). Extract the Prix column (field 2) from the data.tsv file.

    Terminal window
    cut -f2 ~/cut-lab/data.tsv

    Without -d, cut uses the tab by default, perfect for a TSV.

  5. passwd file (colon). Extract the user name (field 1) and the shell (field 7) from passwd.txt.

    Terminal window
    cut -d':' -f1,7 ~/cut-lab/passwd.txt

    The passwd file uses : as its delimiter; the shell is the 7th field.

  6. Extract by character. Extract the first 12 characters of each line of access.log (the IP address).

    Terminal window
    cut -c1-12 ~/cut-lab/access.log

    -c1-12 extracts characters 1 to 12, useful for fixed-width formats.

  7. Combine with other commands. List the names of the users holding the admin role in users.csv.

    Terminal window
    grep ',admin,' ~/cut-lab/users.csv | cut -d',' -f2

    grep filters the lines containing admin, then cut extracts the name from them.

  8. Invert the selection. Print every column of users.csv except the salary (field 5).

    Terminal window
    cut -d',' -f5 --complement ~/cut-lab/users.csv

    --complement inverts the selection: everything but field 5.

Progressive exercises

Eight exercises to validate your mastery. All of them work on the files of the ~/cut-lab lab (or on /etc/passwd). Search on your own first, then unfold the solution to check yourself.

Foundation level

These three exercises cover the basic move: one delimiter, one or two fields, the /etc/passwd file.

Exercise 1, extract a CSV column. Extract only the emails (3rd column) from users.csv. Hint: the CSV uses the comma as its delimiter.

Show the solution
Terminal window
cut -d',' -f3 ~/cut-lab/users.csv

-d',' sets the comma delimiter, -f3 selects the 3rd field.

Exercise 2, list the system users. List the user names from /etc/passwd. Hint: the passwd file uses : as its delimiter, the name is the 1st field.

Show the solution
Terminal window
cut -d':' -f1 /etc/passwd

/etc/passwd is colon-delimited; the user name is field 1.

Exercise 3, several columns. Extract the name and the salary (columns 2 and 5) from users.csv. Hint: separate the field numbers with commas.

Show the solution
Terminal window
cut -d',' -f2,5 ~/cut-lab/users.csv

-f2,5 selects fields 2 and 5, printed in file order.

Composition level

These exercises bring in ranges, character mode and the inverted selection.

Exercise 4, range of columns. Extract columns 2 to 4 from the data.tsv TSV file. Hint: no need for -d on a tab-separated file.

Show the solution
Terminal window
cut -f2-4 ~/cut-lab/data.tsv

Without -d, cut uses the tab; -f2-4 is a range of fields.

Exercise 5, extract by character. Extract the first 10 characters of each line of access.log. Hint: use -c, not -f.

Show the solution
Terminal window
cut -c1-10 ~/cut-lab/access.log

-c1-10 extracts characters 1 to 10 (fixed positions).

Exercise 6, invert the selection. Print every column of users.csv except the 3rd (email). Hint: --complement inverts the selection.

Show the solution
Terminal window
cut -d',' -f3 --complement ~/cut-lab/users.csv

--complement prints everything but field 3.

Industrialisation level

Here cut becomes one link of a pipeline, between grep and sort.

Exercise 7, grep + cut pipeline. List the shells of the users whose home directory is under /home/. Hint: filter with grep before extracting with cut.

Show the solution
Terminal window
grep ':/home/' /etc/passwd | cut -d':' -f7

grep filters the lines containing /home/, cut extracts the shell from them (field 7).

Exercise 8, count unique values. Count how many users hold each role in users.csv. Hint: combine cut, sort and uniq -c.

Show the solution
Terminal window
cut -d',' -f4 ~/cut-lab/users.csv | tail -n +2 | sort | uniq -c

cut extracts the role, tail -n +2 skips the header, sort | uniq -c counts the occurrences.

Troubleshooting

When cut does not return what you expect, the problem almost always comes from the delimiter. Here is how to diagnose it, then how to read the error messages.

Diagnostic methods

These four commands run in order: first identify the real separator, then count the columns, then test on a single line before launching the full processing. cat -A is the most useful of the four: it makes visible what the eye cannot see, a tab (^I) disguised as a run of spaces, or a Windows carriage return (^M$) glued to the last field.

Terminal window
# Show special characters to identify the real delimiter
cat -A fichier.csv | head -1 # ^I = tab, $ = end of line
# Count the number of columns
head -1 fichier.csv | tr ',' '\n' | wc -l
# Test the split on a single line
head -1 fichier.csv | cut -d',' -f2
# Print each field, numbered
head -1 fichier.csv | awk -F',' '{ for (i=1; i<=NF; i++) print i": "$i }'

Frequent errors

The error messages of cut are all emitted before reading a single line. They therefore concern the command line, never the data. If cut runs without a word but returns a wrong result, the problem lies elsewhere: wrong delimiter, or non-existent field.

Error messageProbable causeFix
cut: invalid range with no endpointWrong range syntax (-f- alone)Correct it: -f1-5, -f3- or -f-3
cut: you must specify a list of bytes, characters, or fieldsNo -c, -b or -f optionAdd -f for fields or -c for characters
cut: the delimiter must be a single characterMulti-character delimiterUse a single character, or switch to awk
cut: an input delimiter may be specified only when operating on fields-d combined with -c or -bDrop -d, or switch to field mode with -f
cut: only one type of list may be specifiedTwo modes at once, for example -f and -cKeep a single mode; Debian 13 words it only one list may be specified
cut: fields are numbered from 1Field 0 requested (-f0)Numbering starts at 1: -f1

cut cheat sheet

The five tables below condense everything demonstrated above. They are meant to be skimmed before writing a command, not learnt by heart as an exhaustive reference.

Syntax

Three forms cover almost every use: extraction by field, extraction by position, and reading from a pipe. Note that the file is always the last argument, and that it can simply be left out when cut receives its data on standard input.

FormRoleExample
cut -d'X' -f N fichierExtracts field N with delimiter Xcut -d',' -f2 data.csv
cut -c N-M fichierExtracts characters N to Mcut -c1-10 log.txt
cmd | cut …Extracts from a pipecat f.csv | cut -d',' -f1

Options

-f, -c and -b are mutually exclusive: cut refuses to combine two of them. -d only makes sense with -f, and cut refuses it in character or byte mode. The delimiter must fit in a single character and, if it means something to the shell (|, ;, space), it must be protected by single quotes.

OptionRoleExample
-d'DELIM'Sets the delimiter (default: tab)-d',' -d':' -d'|'
-fSelection by field (with delimiter)-f1 -f2,4 -f1-3
-cSelection by character (position)-c1-10 -c5,10,15
-bSelection by byte-b1-10
-sOnly prints lines with a delimitercut -d':' -f1 -s
--complementInverts the selection-f3 --complement
--output-delimiterChanges the output delimiter--output-delimiter=';'

Field selection (-f)

Numbering starts at 1, not 0: the first field is -f1. Whatever the form used, cut always returns the fields in file order; writing -f3,1 reorders nothing.

FormRoleExample
-f NField N only-f2
-f N,M,PFields N, M and P-f1,3,5
-f N-MFields N to M-f2-5
-f N-From field N to the end-f3-
-f -NFrom the start to field N-f-4

Character selection (-c)

This mode only suits fixed-width formats: mainframe outputs, logs aligned to the column, dumps with a constant template. As soon as a column can vary by one character, the split goes wrong on every following line. Reminder: on Debian and Ubuntu, these positions are counted in bytes, so avoid them on accented text.

FormRoleExample
-c NCharacter N only-c5
-c N-MCharacters N to M-c1-20
-c N,M,PPrecise, non-contiguous characters-c1,5,10

Common pipelines

cut shows its full value in the middle of a pipe, never alone. Position matters: filtering with grep before cut reduces the volume processed; sort must come before uniq -c, otherwise the count only groups consecutive duplicates. With xargs -I{}, make sure the data set is clean: an empty field would trigger a command without an argument.

ChainRoleExample
grep | cutFilter then extractgrep admin f.csv | cut -d',' -f2
cut | sort | uniqExtract then countcut -d',' -f3 f.csv | sort | uniq -c
cut | xargsExtract then runcut -d':' -f1 /etc/passwd | xargs -I{} id {}

Mastery checklist

You master cut when you can tick each of these points, from the delimiter to the choice between cut and awk:

  • I can extract a field with -d and -f
  • I can extract several fields (-f1,3,5)
  • I can use ranges (-f2-5, -f3-, -f-4)
  • I can extract by position with -c
  • I know the tab is the default delimiter
  • I can use --complement to invert the selection
  • I can combine cut with grep and sort
  • I know when to use awk rather than cut

Conclusion

The cut command is a simple but effective tool to extract columns from delimited files. Its concise syntax makes it the ideal tool for quick extractions on CSV, TSV, passwd files or fixed-format logs. For more complex needs (multiple spaces, quotes, calculations), prefer awk, which offers more flexibility.

Key points

  • cut extracts by field (-d + -f) or by position (-c), one mode at a time.
  • Without -d, the delimiter is the tab: a CSV then comes out whole.
  • The delimiter is a single character, and a run of spaces does not make one: switch to awk.
  • Fields always come out in file order, -f3,1 reorders nothing.
  • A non-existent field returns empty output without an error: count the columns before writing the command.
  • --complement inverts the selection, -s drops the lines without a delimiter.
  • -c counts bytes on Debian and Ubuntu, characters on RHEL and AlmaLinux: avoid it on accented text.

Knowledge check

Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer

Is this project useful to you?

The guides, courses, quizzes and labs stay free. If you use them regularly, you can contribute to their upkeep and development.

Become a supporting member (new tab) One-time support (new tab) Learn more

Follow the project on LinkedIn