Challenge - 5 Problems
Cut Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Extract specific columns using cut
Given a file
What is the output of the command
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?Attempts:
2 left
💡 Hint
Remember that
-d sets the delimiter and -f selects fields by their position.✗ Incorrect
The command uses comma as delimiter and extracts fields 2 and 4 from each line. So from the first line, 'banana' and 'date' are extracted, and similarly for other lines.
💻 Command Output
intermediate2:00remaining
Using cut with byte positions
Consider a file
What is the output of
file.txt containing:abcdefg hijklmn opqrstu
What is the output of
cut -b2-4 file.txt?Attempts:
2 left
💡 Hint
The
-b option extracts bytes by position, starting at 1.✗ Incorrect
The command extracts bytes 2 to 4 from each line. For 'abcdefg', bytes 2-4 are 'bcd', for 'hijklmn' they are 'ijk', and for 'opqrstu' they are 'pqr'.
🔧 Debug
advanced2: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?Attempts:
2 left
💡 Hint
Think about what happens if the delimiter does not match the file content.
✗ Incorrect
If the delimiter specified does not exist in the file, cut treats the entire line as one field and prints it entirely. No error is raised.
🚀 Application
advanced2:00remaining
Extract columns with multiple delimiters
You have a file
Which command extracts the 'age' and 'country' fields correctly?
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?
Attempts:
2 left
💡 Hint
Try to split first by one delimiter, then by the other.
✗ Incorrect
First, splitting by '|' and taking field 2 extracts 'age,city'. Then cutting that by ',' and taking field 2 extracts 'city' or 'country' depending on position. Here, the second cut extracts 'country' from the second delimiter-separated part.
🧠 Conceptual
expert3:00remaining
Understanding cut behavior with multibyte characters
Given a file
What is the output of
utf8.txt containing:café naïve jalapeño
What is the output of
cut -b1-4 utf8.txt?Attempts:
2 left
💡 Hint
Remember that cut -b counts bytes, not characters, and UTF-8 characters can be multiple bytes.
✗ Incorrect
The accented characters like 'é' and 'ï' use multiple bytes in UTF-8. Cutting by bytes can split these characters, resulting in invalid byte sequences shown as replacement characters (�).