0
0
Linux CLIscripting~20 mins

cut (extract columns) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cut Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Extract specific columns using cut
Given a file data.txt with the following content:
apple,banana,cherry,date
red,yellow,red,brown
sweet,sweet,tart,sweet

What is the output of the command cut -d',' -f2,4 data.txt?
A
apple,cherry
date,red
red,tart
B
banana,date
yellow,brown
sweet,tart
C
banana,date
red,brown
sweet,sweet
D
banana,date
yellow,brown
sweet,sweet
Attempts:
2 left
💡 Hint
Remember that -d sets the delimiter and -f selects fields by their position.
💻 Command Output
intermediate
2:00remaining
Using cut with byte positions
Consider a file file.txt containing:
abcdefg
hijklmn
opqrstu

What is the output of cut -b2-4 file.txt?
A
bcd
ijk
pqr
B
abc
hij
opq
C
bcd
hij
pqr
D
bcd
ijk
opq
Attempts:
2 left
💡 Hint
The -b option extracts bytes by position, starting at 1.
🔧 Debug
advanced
2:00remaining
Identify the error in cut command usage
What error will the command cut -f1-3 -d',' file.csv produce if file.csv contains tab-separated values instead of commas?
Acut: file.csv: No such file or directory
BNo output because no delimiter ',' found, so entire lines are printed
Ccut: invalid delimiter ','
Dcut: field list syntax error
Attempts:
2 left
💡 Hint
Think about what happens if the delimiter does not match the file content.
🚀 Application
advanced
2:00remaining
Extract columns with multiple delimiters
You have a file records.txt with lines like:
name|age,city|country
Alice|30,New York|USA
Bob|25,London|UK

Which command extracts the 'age' and 'country' fields correctly?
Acut -d'|' -f2 records.txt | cut -d',' -f2
Bcut -d',' -f1 records.txt | cut -d'|' -f2
Ccut -d'|' -f2,4 records.txt
Dcut -d',' -f2,4 records.txt
Attempts:
2 left
💡 Hint
Try to split first by one delimiter, then by the other.
🧠 Conceptual
expert
3:00remaining
Understanding cut behavior with multibyte characters
Given a file utf8.txt containing:
café
naïve
jalapeño

What is the output of cut -b1-4 utf8.txt?
A
caf
naï
jala
B
café
naïv
jala
C
caf�
naï
jala
D
alaj
vïan
éfac
Attempts:
2 left
💡 Hint
Remember that cut -b counts bytes, not characters, and UTF-8 characters can be multiple bytes.