0
0
Linux CLIscripting~10 mins

cut (extract columns) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - cut (extract columns)
Input text or file
Specify delimiter or default tab
Specify fields or character positions
cut extracts specified columns
Output extracted columns
The cut command reads input, uses a delimiter to split columns, extracts specified columns, and outputs them.
Execution Sample
Linux CLI
echo "apple,banana,cherry" | cut -d',' -f2
Extracts the second column (banana) from a comma-separated string.
Execution Table
StepInputDelimiterFieldsActionOutput
1"apple,banana,cherry"','2Split input by ','["apple", "banana", "cherry"]
2["apple", "banana", "cherry"]','2Extract field 2"banana"
3"banana"N/AN/APrint outputbanana
💡 All specified fields extracted and printed; command ends.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
input_line"apple,banana,cherry""apple,banana,cherry""apple,banana,cherry""apple,banana,cherry"
delimitertab (default)','','','
fieldsnone222
split_fieldsnone["apple", "banana", "cherry"]["apple", "banana", "cherry"]["apple", "banana", "cherry"]
outputnonenone"banana""banana"
Key Moments - 3 Insights
Why does cut use a delimiter and what happens if I don't specify one?
cut uses the delimiter to know where to split the input into columns. If you don't specify one, it uses the tab character by default (see execution_table step 1).
What does the -f2 option mean in the cut command?
-f2 tells cut to extract the second field (column) after splitting by the delimiter, as shown in execution_table step 2.
Can cut extract multiple columns at once?
Yes, you can specify multiple fields like -f1,3 to extract first and third columns. This example shows a single field for simplicity.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output after step 2?
A"banana"
B"apple"
C"cherry"
D"apple,banana,cherry"
💡 Hint
Check the 'Output' column in execution_table row for step 2.
At which step does cut split the input string into fields?
AStep 2
BStep 1
CStep 3
DNo splitting occurs
💡 Hint
Look at the 'Action' column in execution_table to find when splitting happens.
If the delimiter was not specified, what delimiter would cut use by default?
AComma ','
BSpace ' '
CTab '\t'
DSemicolon ';'
💡 Hint
Check variable_tracker for the initial delimiter value.
Concept Snapshot
cut command extracts columns from text.
Use -d to set delimiter (default is tab).
Use -f to specify which columns to extract.
Example: cut -d',' -f2 extracts second column from comma-separated input.
Outputs only the selected columns.
Full Transcript
The cut command takes input text or a file and splits it into columns using a delimiter. By default, the delimiter is a tab character. You specify which columns to extract using the -f option. For example, echo "apple,banana,cherry" | cut -d',' -f2 splits the input by commas and extracts the second column, which is "banana". The command outputs only the selected columns. This process involves reading the input, splitting it by the delimiter, extracting the requested fields, and printing them. If no delimiter is specified, cut assumes tab. You can extract multiple columns by listing them with commas in the -f option.